Hi Greg,
On Sat, 2009-08-22 at 13:10 -0700, [email protected] wrote:
> I am very new to RoR (this is my second day).
Welcome!
> I have started my first
> application, and want to follow best practices as much as possible. I
> created a select box that lists all the items in a table column on a
> new.html.erb page. I then realized I needed to create one on the edit
> page. I want to use this select box on several other pages as well.
>
> Trying to keep with D.R.Y. I am wondering if there is a better way to
> do this, instead of putting this statement on every page.
>
> <%= select("note", "project_id", Project.find(:all).collect {|p|
> [p.name, p.id]}) %>
Short answer... maybe. You could refactor it into a partial but a
one-liner partial usually doesn't make much sense. One part of the DRY
rationale is about minimizing lines of code in the code base. That's
goodness, but with one-liners you're actually increasing the number of
lines of code by one and the size question always needs to be balanced
against the performance hit of initializing another class. Don't get
too anal with DRY. Opinions vary but, IMO, the real value of DRY is to
minimize the number of places you have to go to make changes. So, if
you think this select is likely to be used in a lot of places and is
likely to change, then you should consider moving it to a partial more
strongly than if it's not likely to change.
HTH,
Bill
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---