开发者

How do I map all actions for a controller to the top-level in Rails?

开发者 https://www.devze.com 2023-01-17 08:37 出处:网络
Whenever I develop sites using Rails, I create a controller called \"fr开发者_开发技巧ont\" which has actions like \"index,\" \"how,\" and \"about.\" So, the home page, \"How It Works,\" and \"About U

Whenever I develop sites using Rails, I create a controller called "fr开发者_开发技巧ont" which has actions like "index," "how," and "about." So, the home page, "How It Works," and "About Us" pages can be accessed via /, /how/, and /about. My routes look like this:

map.root :controller => "front", :action => "index"

map.connect 'how', :controller => 'front', :action => 'how'
map.connect 'about', :controller => 'front', :action => 'about'

I have two questions:

1) Is this a good organization?

2) Is there a way to add one route to make all actions in the "front" controller accessible via /[action]?


I sometimes have this route as the very last one:

map.connect ':action', :controller => 'main'

...to handle the all-actions thing you mention. As for organization, I think it always depends on the app, what it is, etc. Throw in a little personally preference and I think you're on the right track :)

0

精彩评论

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

关注公众号