Rails: How to retrieve URL of Paperclip uploads?
I am having trouble retrieving the URL of images uploaded via Paperclip.
I set the URL using the following code in my开发者_如何学运维 model:
has_attached_file :banner,
:path => "/www/banners/:foo-:id.:extension",
:url => "http://example.com/:foo-:id.:extension"
In my views, I can retrieve the URL just fine by running @gallery.banner.url
The problem arises when I try to retrieve the same banner.url in a rake task. There is no column for url in the database table, so how does my controller and view know what it is?
My guess is this has something to do with the controller using Gallery.find to retrieve the object, whereas my rake task uses Gallery.where to find the objects.
I am using Rails 3 and loading the Rails environment in the rake task.
Your controller and view know where it is because you've specified the URL in your 'has_attached_file' parameters. I.e. ':path'
精彩评论