# Lots of controllers, one page

**URL:** <https://www.ruby-forum.com/t/lots-of-controllers-one-page/107885>\
**Category:** Rails\
**Created:** [June 27, 2007, 4:27am UTC](https://www.ruby-forum.com/t/lots-of-controllers-one-page/107885 "2007-06-27T04:27:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [June 27, 2007, 4:27am UTC](https://www.ruby-forum.com/t/lots-of-controllers-one-page/107885/1 "2007-06-27T04:27:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [June 27, 2007, 4:58am UTC](https://www.ruby-forum.com/t/lots-of-controllers-one-page/107885/2 "2007-06-27T04:58:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [June 27, 2007, 12:30pm UTC](https://www.ruby-forum.com/t/lots-of-controllers-one-page/107885/3 "2007-06-27T12:30:42Z")

</div>

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

Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
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

On Jun 26, 2007, at 7:26 PM, Jables wrote:

> >

* * *

Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user  
panel and lay it on us.

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [June 27, 2007, 1:36pm UTC](https://www.ruby-forum.com/t/lots-of-controllers-one-page/107885/4 "2007-06-27T13:36:50Z")

</div>

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
