user984621
user984621

Reputation: 48443

Rails - cannot display an image uploaded to Amazon S3

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...

Upvotes: 0

Views: 251

Answers (2)

Casper
Casper

Reputation: 34308

Not adverts, but commercials? So should it not be something like:

@user.commercials.first.image.url

Upvotes: 1

marcel salathe
marcel salathe

Reputation: 252

Assuming foo as the name of the commercial instance

<%= image_tag foo.image.url(:medium) %>

Upvotes: 0

Related Questions