I'm trying to follow along with Ryan Bates CarrierWave Rails Cast http://railscasts.com/episodes/253-carrierwave-file-uploads, but some things have appeared to change since he made it.
Ryan installs carrier wave on the Painting class
class Painting < ActiveRecord::Base
attr_accessible :gallery_id, :name, :image
mount_uploader :image, ImageUploader
end
and then to display the image he does this
<%= image_tag painting.image_url%>
I assume that CarrierWave provides the painting
method. I installed Carrier Wave on the User class
class User < ActiveRecord::Base
attr_accessible :name, :email, :image
mount_uploader :image, ImageUploader
end
When I tried to do this
<%= image_tag user.image_url %>
I got an "undefined local variable or method for 'user'"
error message
When I tried this
<%= image_tag User.image_url %>
I got undefined method
image_url' for # Class:0x0000010248e560>`
This latter error message surprised me, because when I did rake routes
it showed me this url
image GET /images/:id(.:format) {:action=>"show", :controller=>"images"}
This is the file path to the uploaded image
/uploads/user/image/3/cadman.png
but I can't figure out how to display it using a Rails method (i.e. not just img src)
Use instance variable @user
instead of local variable (that is undefined):
<%= image_tag @user.image_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