Lots of controllers, one page.

I have a site with a complex database and about 10 models. The main page of the site has around 5 tables/models bringing data in, so conceptually it seems like I should use a controller on each model. Is there a way to render multiple controllers on a page or am I going about this the wrong way. I'd like to keep the size of my controllers down so writing the entire application in one controller seems like a bad solution. Can anyone suggest anything?

It can appear that way at first. One of the really good sessions at RailsConf reminded us to keep the controllers thin.

Put all your business logic in the models. The controllers are really just intended to assemble data from the models for presentation by the views. So, controllers are more related to views than to models. They assemble the data and the view formats it and gives the user a way to poke it. The controller than does something as a result of the poke by the user, and it all starts over.

Having only one controller for a one page application sounds just fine. But, all it should do is fetch a few records and possibly traverse a few associations, then hand off to the view.

Michael

I’m also trying to find the correct way to structure a rails application. Michael’s advice is the first that I’ve seen that addresses this. Can I ask if anyone knows of any resources that cover the correct way to architect a rails application? Everything I’ve found so far describes the correct syntax of the code rather than how to structure the code. I guess I’m looking for something that covers rails design patterns.

Thanks to anyone who can help with this.

David

i have an app similar to the one you described. I have about 8 models that have to be referenced for the main page of our site. The way i do it is with a lot of partials, that way, the piece of page that i am rendering on the main page always more or less from a controller associated with what i want to display, and, as listed above, i try to keep most of my real logic in the models. Don't know if this setup is ideal, but it does make things easier to find sitewide. shawn