Reputation: 1300
In my applications routes.rb I have defined three routes like the following
map.signup '/signup', :controller => 'users', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
Is it possible for me to get the controller and action name for a particular path?
I am looking for some method like this...
def current_routes(a)
end
should return :controller => 'users', :action => 'new'
if I call current_routes('signup_path')
Upvotes: 1
Views: 1229
Reputation: 5791
Try like this
ActionController::Routing::Routes.recognize_path("/posts/")
If you only have a string with your route (like "signup_path"), then I guess in the context you're using this you should be able to do
ActionController::Routing::Routes.recognize_path(send("signup_path".to_sym))
Upvotes: 3