RAILS: link_to current page

Using Rails 3.

I wanted to generate a link to the current page being viewed, with some extra parameters, but couldn’t find an easy way just by browsing the docs. It turns out this is quite easy:

    link_to "My Link", url_for(my_params)

The url_for helper fills parameters like :controller and :action using the current request information, if they are not provided in my_params.

Thanks to:

http://stackoverflow.com/questions/2543576/rails-link-to-current-page-and-passing-parameters-to-it

This entry was posted in programming and tagged , . Bookmark the permalink.

Leave a comment