link_to accepts the same options as url_for . Having said that there is no :type option, and in fact it does not accept blocks, so I assume that the reason your second example works is because it is within the scope of the book. As Tom mentioned in the answer to this answer, passing a block to link_to can be used as a replacement for the first argument (link text).
If Book is a resource, you can get the link_to to create the URL you are looking for by passing it one of the convenient resource routes you automatically generate. Run rake routes before trying the following:
<%= link_to "Edit", edit_book_path(book) %>
Otherwise, you can explicitly indicate to which controller / action you want to bind:
<%= link_to "Edit", :controller => "books", :action => "edit", :id => book %>
Happy hack.
EDIT: Almost forgot, you can add query strings to bypass them after you declare the identifier of the object you are referencing.
<%= link_to "Edit", edit_book_path(book, :query1 => "value", :query2 => "value")
Will the product be /books/1/edit?query1=value&query2=value . As an alternative:
<%= link_to "Edit", :controller => "books", :action => "edit", :id => book, :query1 => "value", :query2 => "value" %>
Damien wilson
source share