link_to
takes the same options that url_for
does. Having said that, there is no :type
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. As mentioned by Tom in a reply to this answer, passing a block to link_to
can be used as a replacement for the first argument (the link text).
If Book is a resource, you can get the link_to
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 rake routes
before you try this:
<%= link_to "Edit", edit_book_path(book) %>
Otherwise, you can explicitly state what controller/action you want to link to:
<%= link_to "Edit", :controller => "books", :action => "edit", :id => book %>
Happy hacking.
EDIT: Almost forgot, you CAN add query strings bypassing them in AFTER you declare the id of the object you're linking to.
<%= link_to "Edit", edit_book_path(book, :query1 => "value", :query2 => "value")
Would product /books/1/edit?query1=value&query2=value
. Alternatively:
<%= link_to "Edit", :controller => "books", :action => "edit", :id => book, :query1 => "value", :query2 => "value" %>