[英]In Ruby on Rails, how can I map all actions in a controller to root?
In Ruby on Rails, how can I do the equivalent of this in a more elegant routes line? 在Ruby on Rails中,如何在更优美的路线中做到这一点? I may have to add many of these...
我可能不得不添加许多...
map.connect '/about', :controller => "site", :action => "about"
map.connect '/contact', :controller => "site", :action => "contact"
map.connect '/preview', :controller => "site", :action => "preview"
Thanks! 谢谢!
You can do this: 你可以这样做:
map.connect '/:action', :controller => "site", :action => /about|contact|preview/
The part :action => /about|contact|preview/
makes sure that only the listed words can be used as action
in this route,. :action => /about|contact|preview/
可确保仅列出的单词可以在此路线中用作action
。
但是不要忘了将@Tomas建议的路由移动到您的route.rb的底部,否则它将捕获不应捕获的路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.