Its easy to determine URL in Rails

Rails has made so much easy to generate URL for RESTful resources. You don’t have to write the long route helper method; there exits a short hand method to be used; like

url_for [:edit, @parent_object, @resource_object]


When using book_article_path, you can just pass in instances of Book and Article instead of the numeric IDs:

<%= link_to 'Article details', book_article_path(@book, @article) %>

Moreover, you can use url_for with a set of objects, and Rails will automatically determine which route you want to generate:

<%= link_to 'Ad details', url_for([@book, @article]) %>

If you want any specific :action then try

<%= link_to 'Ad details', url_for([:edit, @book, @article]) %>

Some More

If you wanted to link to just a book:

<%= link_to 'Book details', @book %>

If you want to link to nested resource then

<%= link_to 'Article details', [@book, @article] %>

Note: the above technique will only work with link_to helper method.



Some useful links