How do I map all actions for a controller to the top-level in Rails?
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 :)
精彩评论