views:

17

answers:

1

Whenever I develop sites using Rails, I create a controller called "front" 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]?

+1  A: 

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 :)

thenduks
Ah, simpler than I thought. I will give this a try.
Chad Johnson
The tricky part with this is that you may have trouble with priority. Make sure you're thinking logically about when you want this route to match (usually after everything else) and you should be good.
thenduks
Well, putting this line in my routes jacks with AuthLogic authentication. Authentication uses the 'UserSessionsController', and when /user_session is visited, the app tries to access the (non-existent) 'user_session' method in the MainController. So I guess I have to add a route for each top-level page to the routes file manually. This kind of sucks.
Chad Johnson
Make sure this is _the last route_. If AuthLogic still has trouble then I'd ask on their newsgroup or something, pretty annoying to add last-matched routes that are required...
thenduks