Andrew says:

I changed this line:

<%= image_tag(product.image_url) %>

... to …

<%= link_to(image_tag(product.image_url), 
            line_items_path(:product_id => product), 
            html_options = {:method => :post}) %>

Arun says:

The above works fine, but when I click the image, it directs to line_items show action, instead of cart(http://localhost:3000/line_items?product_id=3). Andrew, did you face this? How to direct it to cart’s show action?

Arun says:

I did it. Instead of using HTML call to post, I invoked the create method through rails. Works fine.

<%= link_to(image_tag(product.image_url), line_items_path(:product_id =>product), :method=> "create") %>

Martin says:

But finally “user friendly way” is:

<%= link_to image_tag(product.image_url, {:border => "0", :title => "Push it into cart!"}),
                      line_items_path(:product_id => product), {:method => :post} %>

Mike says:

Improving upon what Martin posted, I wanted to store the image border style in my style sheet, so I specified a CSS class using :class

<%= image_tag(product.image_url, :class => "image_link")

And added this to my CSS file:

.image_link {
    border: 0;

Mo says:

Not sure why, but with the solutions above, right clicking the image actually invokes the click-action (creating an item_line) and not only the popup menu from the browser (using Firefox). It’s because of the javascript, but that’s beyond my knowledge :-( ... any ideas? Thx!

Bruce says:

@Mo the issue seems to be a bug in Firefox. Try in Safari and you see the expected behaviour.