On Monday 01 February 2010, Marnen Laibow-Koser wrote: > Michael Schuerig wrote: > [...] > > >> What's the point of helper "polymorphism"? I'm having trouble > >> coming up with a good use case for it. > > > > format_value, cancel_link are just two examples where generic names > > are perfectly understandable within a context, although they may > > need to do different things depending on context. > > Does cancel_link need to do different things depending on context? > If so, what?
Let's say that, in an edit view, you want cancel_link to generate a link back to the corresponding list view. But you might want it to do something else. At any rate, I want a common name, but possibly different concrete functionality. [...] > > <%= format_money foo.amount %> > > <%= format_money bar.amount %> [...] > What I would do instead is make foo.amount and bar.amount Money > objects (using composed_of if ActiveRecord is involved). Then > define Money#to_s, and the view will simply be > > <%= foo.amount %> > <%= bar.amount %> > > I don't see any need for a helper here. Am I missing something? Assuming foo and bar are model instances, how would you differentiate that sometimes you'd like to display only whole units, or even "kilobucks" (k$), and at others everything to the last cent. In one case with, in another without currency unit. And let's not forget about decimal and thousand separators. These are strictly UI-issues that don't belong in the model. Now, if foo and bar were presenter instances, things would look different. Michael -- Michael Schuerig mailto:mich...@schuerig.de http://www.schuerig.de/michael/ -- 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-t...@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.