I'm not sure if I understand how Paperclip works, but as far as I can tell, the default place to save uploads is in the /public folder. When I upload my photo on my development, they appear correctly in (and I can open them in the file structure):
/public/bookmarks/:id/:style.:extension
However, when I do bookmark.photo.url
, I get something like:
/system/bookmarks/thumbs/000/000/042/original/filename.png?1362768439
Here's my bookmark.rb
:
has_attached_file :photo,
:styles => { :medium => ["512x512>", :jpg], :thumb => ["200x200#", :jpg] }
:default_url => "public/bookmarks/default/:style.png",
:path => "assets/content/bookmarks/:id/:style.:extension"
Am I missing something here? Isn't Paperclip meant to deal with this stuff for me, or have I got something wrong in the config?
UPDATE
If I add the :path
and :url
in the first answer, I get:
<img src="/assets/bookmarks/44/original.jpg?1362775508">
Whereas I should be getting:
<img src="/bookmarks/44/original.jpg?1362775508">
But, if I comment out the :url
option, instead of getting:
this, which is the default not-found image size, I get:
this, which is the same width as the image I have on my filesystem, but the wrong height, and not found. This happens in both Chrome and Safari with clean caches. When I go to the URL, I get a 404. I can also confirm that the image is stored correctly on the filesystem and is viewable from the back end.
The behavior you describe it's a little weird. I suggest you set both :url and :path in a way similar to this:
url: '/:class/:id/:style.:extension',
path: ':rails_root/public:url'
This means images will be stored in:
"#{Rails.root}/public/bookmarks/:id/:style.:extension"
And the URL will give you something like:
/bookmarks/bookmarks/1/thumbs.png
Note that you can do this using config.paperclip_defaults
in "application.rb", so you don't have to do it on each model. And you can override this on "production.rb" if you want a different path or storage, e.g.:
config.paperclip_defaults = config.paperclip_defaults.merge({
storage: :s3,
path: 'project_name/public:url'
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With