In Ruby on Rails, how can I do the equivalent of this in a more elegant routes line? 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,.
但是不要忘了将@Tomas建议的路由移动到您的route.rb的底部,否则它将捕获不应捕获的路由。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.