Fernando Perez
2010-Aug-11 16:03 UTC
Paperclip generating crap urls on server, works on dev
Hi, I have the following: has_attached_file :data, :styles => {:theora => {:format => "ogv"}, :still => {:format => "jpg"}, :small => {:format => "jpg"}}, :url => "/uploads/products/:basename:suffix.:extension", :path => ":rails_root/uploads/products/:basename:suffix.:extension" Let''s say I upload a video called video.mp4, now I want paperclip to generate the url: object.data.url(:still) => /some/url/video.jpg But for some reason on my server, paperclip generates: /some/url/video.mp4 Moreover, if I update code and restart the server, paperclip will correctly generate the .jpg extension the first time, but if I reload the page, it messes up and goes back to .mp4. Everything works fine on my dev machine (mac mongrel+nginx), and this strange behavior only happens on the server (freebsd passenger+nginx). Did anyone experience such weird thing? It''s driving me crazy!. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Perez
2010-Aug-11 16:50 UTC
Re: Paperclip generating crap urls on server, works on dev
Okay so it has to do with caching. On my dev machine, if I switch to production environment I get the same behavior. I don''t know what''s the solution. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Parker Selbert
2010-Aug-11 21:40 UTC
Re: Paperclip generating crap urls on server, works on dev
Fernando Perez wrote:> Okay so it has to do with caching. On my dev machine, if I switch to > production environment I get the same behavior. I don''t know what''s the > solution.You''re encountering this because Paperclip was originally built to process a file into different sizes of itself, original, medium, thumbnail etc. In that scenario the format stays the same, so if you use a jpg you''ll have a thumbnail jpg as well. When you''re looking at converting to a different format or, in your case, capturing a still it doesn''t check the mime-type for every style it has. There is at least one branch on github where somebody has attempted to solve this, but here is the approach I''ve followed: 1. Create an initializer at # config/initializers/paperclip.rb Paperclip.interpolates :style_extension do |attachment, style| default = File.extname(attachment.original_filename).gsub(/^\.+/, "") case style.to_s when /theora/ then ''ogv'' when /still/ then ''jpg'' else default end end 2. Use that interpolation in your url and path options: :url => "/uploads/products/:basename:suffix.:style_extension", :path => ":rails_root/uploads/products/:basename:suffix.:style_extension" For reference on interpolations: http://rdoc.info/projects/thoughtbot/paperclip Hope it helps! - Parker -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Perez
2010-Aug-12 09:00 UTC
Re: Paperclip generating crap urls on server, works on dev
Parker Selbert wrote:> attempted to solve this, but here is the approach I''ve followed:Hi Parker, thanks for your message, I was considering doing it that way, so I''ll go for it. Best regards, -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Perez
2010-Aug-12 09:12 UTC
Re: Paperclip generating crap urls on server, works on dev
> thumbnail etc. In that scenario the format stays the same, so if you use > a jpg you''ll have a thumbnail jpg as well.Still what''s strange is that it should use the :format option I provided, that''s what''s written in the docs, so if a jpeg is upload, one of its style can be a png. And by looking at its source code that''s what expected to occur. In dev env it works, but once class caching is turned on, it works once, then craps out. I''ll see what the devs think about it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
fiona-pPy/7Gxx9pKGw+nKnLezzg@public.gmane.org
2010-Aug-14 04:24 UTC
Re: Paperclip generating crap urls on server, works on dev
We encountered this problem too and decided to dig deeper to fix it. You are right about Rails class caching. The Style initializer removes the :format, :geometry and :processors options from the options hash and stores them as an instance variable. When Rails class caching is on, every Style initialized after the first one will not have the :format, :geometry and :processors options passed in, because they were deleted from the class. We''ve created an issue on Paperclip''s Github: http://github.com/thoughtbot/paperclip/issues/issue/277 We forked the repository and made the fix here: git://github.com/pivotal-creationmix/paperclip.git On Aug 12, 5:12 pm, Fernando Perez <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > thumbnail etc. In that scenario the format stays the same, so if you use > > a jpg you''ll have a thumbnail jpg as well. > > Still what''s strange is that it should use the :format option I > provided, that''s what''s written in the docs, so if a jpeg is upload, one > of its style can be a png. And by looking at its source code that''s what > expected to occur. > > In dev env it works, but once class caching is turned on, it works once, > then craps out. I''ll see what the devs think about it. > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fernando Perez
2010-Aug-14 15:57 UTC
Re: Paperclip generating crap urls on server, works on dev
Ok so there is definitely a bug, thanks for sharing your experience. I hope it gets fixed quickly. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Parker Selbert
2010-Aug-14 16:53 UTC
Re: Paperclip generating crap urls on server, works on dev
Nice, thanks for sharing! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.