In my show views whenever I try and display an image using the image_tag builder rails doesn't look for images in the public folder inside of my show views...
For instance:
<%= image_tag "thumbnails/fish.jpg" %>
Will produce this:
ActionController::RoutingError (No route matches [GET] "/uploads/thumbnails/fish.jpg"):
I'm using the paperclip Gem for my upload model and I'm saving uploads to a different folder than the public folder for security reasons, and yes, this show view does occur within the Upload controller...
In my Upload model I use this line to save uploads to a non-public folder:
has_attached_file :upload, :path => ":rails_root/:class/:id/:basename.:extension",
:url => ":rails_root/:class /:id/:basename.:extension"
Rake routes:
upload GET /uploads/:id(.:format) {:action=>"show", :controller=>"uploads"}
PUT /uploads/:id(.:format) {:action=>"update", :controller=>"uploads"}
DELETE /uploads/:id(.:format) {:action=>"destroy", :controller=>"uploads"}
/download/:id(.:format) {:controller=>"uploads", :action=>"download"}
Edit Note: If I explicitly make an img tag and point the src to my image it works fine on my show views so I don't think it's a permission issue.
The answer was fairly simple, and I can't believe Rails is being this picky but I needed to include a forward slash at the beginning of the path as so:
"thumbnails/fish.jpg"
becomes
"/thumbnails/fish.jpg"
I'm still curious as to why this is only a problem on non-index views...
You may need to change this line to true:
config.serve_static_assets = false
in the environment/*.rb file (e.g. development.rb).
Or I have seen where this is a permissions issue on the directory in question so a CHMOD 777 on the directory may resolve it/point you in the right direction.
Here is an SO ticket on a similar issue
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