{"id":6271,"date":"2014-04-15T08:19:45","date_gmt":"2014-04-15T08:19:45","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/15\/ruby-on-rails-link_tag-with-image-tag-talk-to-a-controller-collection-of-common-programming-errors-2\/"},"modified":"2014-04-15T08:19:45","modified_gmt":"2014-04-15T08:19:45","slug":"ruby-on-rails-link_tag-with-image-tag-talk-to-a-controller-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/15\/ruby-on-rails-link_tag-with-image-tag-talk-to-a-controller-collection-of-common-programming-errors-2\/","title":{"rendered":"Ruby on Rails, link_tag with image tag talk to a controller-Collection of common programming errors"},"content":{"rendered":"<p>Hi I&#8217;m currently learning Ruby On Rails and I have a little mistake.<\/p>\n<p>I want to add a hyperlink on my image and when I click on this image <strong>I want to talk to my function &#8216;add_to_cart&#8217;<\/strong>. Right now it&#8217;s currently working with <strong>button_add<\/strong> but not with the function <strong>link_to<\/strong>.<\/p>\n<p>My link_to code:<\/p>\n<pre><code> product.title, :width =&gt; 100, :border =&gt; 1), :id =&gt; product, :action =&gt; 'add_to_cart' %&gt;\n<\/code><\/pre>\n<p>The error:<\/p>\n<pre><code>Unknown action\n\nThe action 'show' could not be found for StoreController\n<\/code><\/pre>\n<p>Hyperlink HTML:<\/p>\n<pre><code>\n   <img decoding=\"async\" width=\"100\" border=\"1\" src=\"\/assets\/images\/cover_test.jpg\" alt=\"Book 2\" \/>\n\n<\/code><\/pre>\n<p>Thanks You for your help :)!<\/p>\n<p><strong>&#8212;&#8212; SOLUTION &#8212;&#8212;<\/strong><\/p>\n<p>I can&#8217;t answer my question but I found the solution. I had a problem with my route.rb configuration, it&#8217;s was creating a conflict with my function index.<\/p>\n<p>Old route.rb config:<\/p>\n<pre><code>match 'store\/:id', :to =&gt; 'store#add_to_cart'\n<\/code><\/pre>\n<p>New route.rb config:<\/p>\n<pre><code>match 'store\/add_to_cart\/:id', :to =&gt; 'store#add_to_cart'\n<\/code><\/pre>\n<p>Here&#8217;s my link_to code:<\/p>\n<pre><code> product.title, :width =&gt; 100, :border =&gt; 1), {:action =&gt; 'add_to_cart', :id =&gt; product} %&gt;\n<\/code><\/pre>\n<p>Thank You @Justin for your help :).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi I&#8217;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 &#8216;add_to_cart&#8217;. Right now it&#8217;s currently working with button_add but not with the function link_to. My link_to code: product.title, :width [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6271","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6271"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6271\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}