I understand how to turn :controller, :action, :etc into a URL. I’m looking to do the reverse, how can the action that the rails router will call be found from the URL?
I understand how to turn :controller , :action, :etc into a URL. I’m looking
Share
someone else might have a shorter way to do this, but if you are just evaluating a URL, then you go to the
ActionController::Routing::RouteSetclassfor a
config.routes.rbthe code to find is:
Right:
Wrong – without the
methodbeing explicitly added, it will default match to/:controller/:action/:id:If you are within the action and would like to know, it is quite a bit easier by calling
params[:action]everything you ever wanted to know about routeset can be found here: http://caboo.se/doc//classes/ActionController/Routing/RouteSet.html#M004878
Hope this helps!