Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Linking to the Current Action (See related posts)

This small snippet shows how to link to the current action. Although it's very easy to do, it doesn't seem to be documented anywhere. This comes in handy when your dealing with partials that are called in multiple actions and controllers.
   1  
   2  <%= link_to "Insert Link Text", :action => controller.action_name %>

Comments on this post

masterkain posts on Apr 07, 2007 at 00:21
I'd rather use request.path instead.
smackjer posts on Apr 25, 2007 at 16:59
masterkain, why would you use request.path? What are the advantages?
timmorgan posts on Apr 26, 2007 at 00:01
I tend to use request.request_uri a lot when I need to link to the current URL (including arguments and such). I didn't know about controller.action_name, but params[:action] will get you the same thing as far as I know. params[:controller] is useful as well.

You need to create an account or log in to post comments to this site.


Click here to browse all 5556 code snippets

Related Posts