繁体   English   中英

Rails 2.3.5:如何获取路线名称

[英]Rails 2.3.5: how to get routes name

在我的应用程序route.rb中,我定义了以下三种路由:

 map.signup '/signup', :controller => 'users', :action => 'new'
 map.login  '/login', :controller => 'sessions', :action => 'new'
 map.logout '/logout', :controller => 'sessions', :action => 'destroy'

我能否获得特定路径的控制器和动作名称?

我正在寻找这样的方法...

def current_routes(a)
end

如果我调用current_routes('signup_path') :controller => 'users', :action => 'new'应该返回:controller => 'users', :action => 'new'

这样尝试

ActionController::Routing::Routes.recognize_path("/posts/")

如果您的路由中只有一个字符串(例如“ signup_path”),那么我想在您正在使用的上下文中,您应该可以

ActionController::Routing::Routes.recognize_path(send("signup_path".to_sym))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM