Rails: how to display image from download

I'm trying to follow along with Ryan Bates CarrierWave Rails Cast http://railscasts.com/episodes/253-carrierwave-file-uploads , but some things seem to have changed since he did this,

Ryan sets the carrier wave in the painting class

class Painting < ActiveRecord::Base attr_accessible :gallery_id, :name, :image mount_uploader :image, ImageUploader end 

and then to display the image that he is making,

 <%= image_tag painting.image_url%> 

I assume CarrierWave provides a painting method. I installed Carrier Wave in the User class

 class User < ActiveRecord::Base attr_accessible :name, :email, :image mount_uploader :image, ImageUploader end 

When I tried to do it

  <%= image_tag user.image_url %> 

I got the error message "undefined local variable or method for 'user'"

When i tried this

 <%= image_tag User.image_url %> 

I got an undefined method image_url 'for #class: 0x0000010248e560> `

This last 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 path to the uploaded image.

 /uploads/user/image/3/cadman.png 

but I can't figure out how to display it using the Rails method (i.e. not just img src)

+4
source share
1 answer

Use the @user instance @user instead of a local variable (i.e. undefined):

 <%= image_tag @user.image_url%> 
+7
source

Source: https://habr.com/ru/post/1391022/


All Articles