views:

64

answers:

3

For example I have a url generated by something_path or something_url methods. I need to know action name from that url.

+3  A: 

You don't need to guess. You can run rake routes from the Terminal/Command Prompt to get a list of all the routes in your application. The output includes the HTTP method used, as well as the controller and action invoked.

John Topley
A: 

If you are in a view, you can use

  • action_name to get access to the processing action
  • controller_name to get access to the processing controller
Simone Carletti
+1  A: 

The routing system of Rails works two ways, it recognizes and builds URLs. You need the recognize_path method, like the following example shows:

ActionController::Routing::Routes.recognize_path('/mycontroller/myaction', :method => :get)

Assuming that the URL was generated with something_path or something_url, it returns:

{ :action => 'myaction', :controller => 'mycontroller' }

From which you are able to extract the action part.

Veger