开发者

Rails 2.3.5: how to get routes name

开发者 https://www.devze.com 2023-02-15 06:54 出处:网络
In my applications routes.rb I have defined three routes like the follow开发者_高级运维ing map.signup \'/signup\', :controller => \'users\', :action => \'new\'

In my applications routes.rb I have defined three routes like the follow开发者_高级运维ing

 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')


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))

0

精彩评论

暂无评论...
验证码 换一张
取 消