Ruby on Rails, link_tag with image tag talk to a controller-Collection of common programming errors

Hi I’m currently learning Ruby On Rails and I have a little mistake.

I want to add a hyperlink on my image and when I click on this image I want to talk to my function ‘add_to_cart’. Right now it’s currently working with button_add but not with the function link_to.

My link_to code:

 product.title, :width => 100, :border => 1), :id => product, :action => 'add_to_cart' %>

The error:

Unknown action

The action 'show' could not be found for StoreController

Hyperlink HTML:


   Book 2

Thanks You for your help :)!

—— SOLUTION ——

I can’t answer my question but I found the solution. I had a problem with my route.rb configuration, it’s was creating a conflict with my function index.

Old route.rb config:

match 'store/:id', :to => 'store#add_to_cart'

New route.rb config:

match 'store/add_to_cart/:id', :to => 'store#add_to_cart'

Here’s my link_to code:

 product.title, :width => 100, :border => 1), {:action => 'add_to_cart', :id => product} %>

Thank You @Justin for your help :).