Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove the action argument from Rails link_to function?
    primarykey
    data
    text
    <p>Not sure how to frame this so here goes....</p> <p>I have the following link_to tag:</p> <pre><code>&lt;%= link_to("My test title",{:controller=&gt;"search", :action=&gt;"for-sale", :title =&gt; listing.title, :search_term =&gt; search_term, :id=&gt; listing.id}) %&gt; </code></pre> <p>and the following custom route in my routes.rb file:</p> <pre><code>map.connect ':controller/:action/:title/search_item/:id', :controller=&gt;'search', :action=&gt;'for_sale' </code></pre> <p>which generates a very nice SEO friendly URL:</p> <pre><code>/search/for-sale/sometitle/searchterm/123456 </code></pre> <p>How can I remove the :action param from both, the problem is when I take out the :action option &amp; change my link_to tag to:</p> <pre><code>&lt;%= link_to("My test title",{:controller=&gt;"search", :title =&gt; listing.title, :search_term =&gt; search_term, :id=&gt; listing.id}) %&gt; </code></pre> <p>and my custom route to:</p> <pre><code>map.connect ':controller/:title/search_item/:id', :controller=&gt;'search', :action=&gt;'for_sale' </code></pre> <p>The URL generated is no longer SEO friendly and very ugly:</p> <pre><code>/search?title=test&amp;search_term=test&amp;id=1141409 </code></pre> <p>My custom route is redirecting to the correct action within the controller so there is no need for action option to be in the URL. Anytime I remove or rename the :action option to something else - the URL gets "distorted", do you know how I can do this?</p> <p>Been trying a number of options but nothing seems to work.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload