Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001597" rel="nofollow noreferrer"><code>link_to</code></a> takes the same options that <a href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000649" rel="nofollow noreferrer"><code>url_for</code></a> does. <del>Having said that, there is no <code>:type</code> option and it doesn't really accept blocks, so my guess is that the reason the your second example works is because it's located within the scope of a Book view.</del> As mentioned by <a href="https://stackoverflow.com/questions/2711294/rails-link-to-with-block-and-get-params/2711571#comment-2736417">Tom</a> in a reply to this answer, passing a block to <code>link_to</code> can be used as a replacement for the first argument (the link text).</p> <p>If Book is a resource, you can get the <code>link_to</code> helper to generate the URL you're looking for by passing it one of the handy, automatically generated resource routes rails makes for you. Run <code>rake routes</code> before you try this:</p> <pre><code>&lt;%= link_to "Edit", edit_book_path(book) %&gt; </code></pre> <p>Otherwise, you can explicitly state what controller/action you want to link to:</p> <pre><code>&lt;%= link_to "Edit", :controller =&gt; "books", :action =&gt; "edit", :id =&gt; book %&gt; </code></pre> <p>Happy hacking.</p> <p><strong>EDIT:</strong> Almost forgot, you CAN add query strings bypassing them in AFTER you declare the id of the object you're linking to.</p> <pre><code>&lt;%= link_to "Edit", edit_book_path(book, :query1 =&gt; "value", :query2 =&gt; "value") </code></pre> <p>Would product <code>/books/1/edit?query1=value&amp;query2=value</code>. Alternatively:</p> <pre><code>&lt;%= link_to "Edit", :controller =&gt; "books", :action =&gt; "edit", :id =&gt; book, :query1 =&gt; "value", :query2 =&gt; "value" %&gt; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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