[Rails] Best Practices question regarding views & controllers

Berin Loritsch
Fri, 03 Mar 2006 14:42:41 -0000

Raphael Schmid wrote:
> Hi List!
>
> I''m reading the Agile book, as many online articles as I can, but
> there''s still some things that are just too hard to answer for
yourself.
> In building my application, I often find myself putting code into my
> views of which I am not quite certain it belongs there.
>
> Where do you usually draw the line? Is it okay to, say, loop through an
> array of hashes that represents table column names and whether they need
> a certain colspan and build the table according to that?
>
> Any advice that you might have would be greatly appreciated!
>

My general rule of thumb is this:

* If we are modifying the model, or finding resources, it belongs in the
controller
* If we are iterating through a list to display items, it belongs in the
view

And for the fuzzy areas where we might have to filter the results, the
view should simply display the items in a set and the controller would
do all filtering.