Finnnn
Finnnn

Reputation: 3580

Using a property of a model in an image tag

How can I use a property of a model in an image tag?

I thought this would work -

      <%= image_tag('#{somemodel.name}.png') %>

But that renders -

<img src="/assets/#{somemodel.name}.png" alt="#{video.name}">

How can I get it to put the name property of somemodel?

Upvotes: 1

Views: 94

Answers (2)

Chowlett
Chowlett

Reputation: 46667

Single quotes don't allow for interpolation. Try

<%= image_tag("#{somemodel.name}.png") %>

or

<%= image_tag(somemodel.name + ".png") %>

Upvotes: 3

U-DON
U-DON

Reputation: 2140

Did you try this?

<%= image_tag(somemodel.name + '.png') %>

Upvotes: 0

Related Questions