Aron Solberg
Aron Solberg

Reputation: 6858

Best way to make an image link in Rails 4?

I want a picture of my product to link to the product show page. I've tried:

<%= link_to product.photos.first.image.url(:small), product%>

which produces

<a href="/products/64">/system/photos/images/000/000/023/small/4462867927_3741423c39_o.jpg?1395899030</a>

I've also tried

          <a href="<%= products_path(product) %>"> <%= image_tag product.photos.first.image.url(:small) %> </a>

which produces:

<a href="/products.64"> <img alt="4462867927 3741423c39 o" src="/system/photos/images/000/000/023/small/4462867927_3741423c39_o.jpg?1395899030"> </a>

And that's not right either. Whats the best way to do this in Rails?

Upvotes: 0

Views: 115

Answers (1)

tirdadc
tirdadc

Reputation: 4703

<%= link_to image_tag(product.photos.first.image.url(:small)), product %>

Upvotes: 1

Related Questions