How to use Rails named route helpers with parameters?

To answer your two questions:

  • At the command line, runrake routes to see what routes there are in
    your app. It will show you all the ways you can use the named routes,
    just add “_path” or “_url” to the name of the route which is shown on
    the left.
  • Calling hello_path(@post) will generate a URL to the
    show page for that hello instance.

The way you are calling it is the norm:

<%= link_to "link2", hello_url(:name=> @post.name, :title=>@post.title) %>

However, this may work too:

<%= link_to "link2", hello_url(@post.name, @post.title) %>

Here is some documentation (other than the Rails API) which should help.
http://guides.rubyonrails.org/routing.html

Leave a Comment