I have these two models:
user:
has_many :commercials, :dependent => :destroy, :inverse_of => :user
commercial:
belongs_to :user, :inverse_of => :commercials
has_attached_file :image,
:styles => { :medium => "400x400",
:thumb => "50x50>" }
I just uploaded one image, the image is successfully uploaded to Amazon S3 and saved into the database. But how to display it?
I tried:
<%= image_tag @user.adverts(:medium) %>
or
<%= image_tag @user.adverts.medium.url %>
But none of above is working...
Not adverts
, but commercials
? So should it not be something like:
@user.commercials.first.image.url
假设foo
为商业实例的名称
<%= image_tag foo.image.url(:medium) %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.