Thanks for both posts regarding DRY and too DRY.  Some very good
points.

On Feb 28, 7:08 am, Maurício Linhares <mauricio.linha...@gmail.com>
wrote:
> On Sat, Feb 28, 2009 at 1:32 AM, ericindc <ericmilf...@gmail.com> wrote:
>
> > Ok, I follow having all models respond to "title", but why would
> > implementing the model's "to_s" method be a better approach?  Is it
> > just for consistency, always expecting to_s to return what the partial
> > should display?  How is that any different that expecting all models
> > to answer to title?
>
> First it's for the sake of consistency, but it's also 'cos the to_s
> method is defined to return a "string representation of the object",
> so if you already have a method that does what you want, why create
> another one or why care about creating another method that "returns a
> string representation of the object"?

Thanks, you've been a huge help.

Makes sense for consistency's sake.  My initial concern is about
overriding a core method.  What if I needed to_s elsewhere?  Plus,
wouldn't I be writing more code given that every model must now have a
custom defined to_s method?  Unless adding extra virtual attributes is
bad, would it be less work (given that I'd have to change two models
at this point) to just add a "title" method for those that doesn't
respond to title?

>
> This way you don't need to add extra virtual methods at your models,
> you just expect them to have a good to_s implementation.
>
> > Thanks.  This has been really helpful.  I used your example to create
> > the following.  Thoughts?
>
> >http://pastie.org/402843
>
> It's good, but that's how I'd do it ->http://pastie.org/403009
>
> The more conventions you have, the easier it is to keep things
> consistent in your pages.

I picked up a few good points, but I decided on my implementation
because there are other types of those sidebar boxes.  For instance,
they won't all say "Create New XYZ".  Some will say "My Comments", or
"Add Member".  The images, etc. will change too.

It made sense to me to keep the structure of the box DRY since that
will never change and just plug in my values as needed.  And the only
way I found to do that was what I pastied too.  I'll keep looking at
it though.

>
> -
> Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) 
> |http://blog.codevader.com/(en)
--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to