For example I have a url generated by something_path
or something_url
methods. I need to know action name from that url.
views:
64answers:
3
+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
2010-01-06 11:02:18
A:
If you are in a view, you can use
action_name
to get access to the processing actioncontroller_name
to get access to the processing controller
Simone Carletti
2010-01-06 13:08:33
+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
2010-01-08 13:58:08