Re: How to clean up this code?

Patrick Doyle
Fri, 28 Mar 2008 14:09:17 -0000

On Fri, Mar 28, 2008 at 9:41 AM, Ar Chron
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
>
>  Patrick Doyle wrote alot:
Boy did that make me laugh! :-)

>  What I always find interesting is that different people can approach
>  essentially the same problem from very disparate approaches.  But
I''ll
>  weigh in with my two cents...
Thank you... that is _precisely_ what I was hoping for!

>  My categories would go in a table/model all their own. After all, they
I''ve argued myself in and out of that position a couple of times.
Ultimately, I couldn''t see the difference between adding the line of
code that looked like:

  :id => 5, :text => ''QA Testing Protocols'', :min =>
20, :max => 29

to my controller, vs adding an entry to a table in the database.  But
if the more common practice is to put data like that in a model, then
I would like to follow the common practice.

>  I try diligently to keep code out of my views (with varying degrees of
>  success).  Rather than a find(:all) in your controller, could you apply
>  the conditions there so the view just renders the documents it receives
>  (strict MVC adherents would say the view should only render what it is
>  given).
>
Thanks for the tips.  As I looked at the code more carefully (of
course, _after_ submitting my long boring post), I noticed the

@documents = Document.find(:all)

line leftover from the scaffolding.  The way Active Scaffolding works,
you pass the name of the model, not list of data to be displayed, so
that line is superfluous.  However, I now see how I could set my
"cond" condition as an instance variable and simply use that in my
view as the condition.  Thanks... that cleans things up.

>
>  Lastly, and this is strictly a personal preference, I very much like
>  haml for my views as opposed to erb. I got very tired of div, span, and
>  <%= %> spam in my views... Your mileage may vary.
OK... now I''ll go find out what haml is.... thanks for the pointer.