开发者

In Ruby on Rails, how can I map all actions in a controller to root?

开发者 https://www.devze.com 2023-01-03 21:55 出处:网络
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...

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 '/开发者_Python百科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,.


But do not forget to move the route suggested by @Tomas to the bottom of your routes.rb Otherwise it will catch routes that should not be caught.

0

精彩评论

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