I originally had paperclip’s default configuration contain
:url => "/some_path/:basename.:extension"
However, no all the files I’m uploading have extensions, and in those cases, I don’t want the “.” (between basename and extension in the configuration) to be there. So I’d like to do something like this:
:url => lambda { |i| "/some_path/:basename#{".:extension" if i.extension}" }
I tried that and got a “can’t convert Proc into String” error, which tells me that paperclip doesn’t support dynamic configuration of urls the way it does for styles and processors. Any ideas for how else I could do this, the less hack-ish the better?
The short answer is that you replace
with
The more detailed answer is that basename, filename and extension are all interpolations, and you can use any interpolations defined in ‘paperclip/interpolations’ (in paperclip’s lib directory) or define your own.
For example:
assuming, of course, that the model that
has_attached_filealsobelongs_to :cityand that your city object knows today’s temperature.