Topic: Mixed index pages

Typically, I've seen that you generate all your controllers and then route the route of your app to one of them.  That way when you're on localhost:3000 you're actually looking at one of your controllers that handles the main functions.. i.e. localhost:3000/products or some such thing.

I have an app I'm writing where the homepage (index) will pull data from a bunch of different tables, aggregating it into one nice summary view.  Since data is coming from lots of places there's really no great candidate for what to choose when setting up the route to '/'.  I guess I could either:

a. Pick one arbitrarily.  Since it's restful, I'd choose a restful controller.

b. Create a controller specifically for the job (homepage controller or something).  Since it's job would be just to display just on the front page it would be non-restful.

Most of my previous rails experience has been around just getting stuff to work, so I'm only now actually taking the time to think through things like this.  Patience appreciated..

Re: Mixed index pages

viniosity wrote:

a. Pick one arbitrarily.  Since it's restful, I'd choose a restful controller.

I would only do this if the home page is focussed primarily on that model. For example, if you have a bulletin board app the home page may list all the different forums. In that case the forums/index action is a great candidate for the home page (even if it does list a few other things which are secondary).

viniosity wrote:

b. Create a controller specifically for the job (homepage controller or something).  Since it's job would be just to display just on the front page it would be non-restful.

This is most likely what you'll want to do. I have created a Home controller in the past and it has worked great.

If the home page is extremely simple (mostly static content) then it may not really be worthy of a full-out controller (with just one action). In that case I prefer to place it in some kind of info/static controller which handles these mostly static pages which don't fit into their own controller (such as an "about" page).

Railscasts - Free Ruby on Rails Screencasts