Michael Schuerig wrote:
> On Monday 01 February 2010, Marnen Laibow-Koser wrote:
>> 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. 

I think you could just leave the controller name out of link_to.

> But you might want it to do
> something else. At any rate, I want a common name, but possibly
> different concrete functionality.
>

I am hard put to come up with a use case for this is a helper.  I don't 
find your example particularly convincing.

> [...]
>> >   <%= 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.

Probably by having to_s take an optional parameter.

> In one case
> with, in another without currency unit. And let's not forget about
> decimal and thousand separators.

Same answer.

> 
> These are strictly UI-issues that don't belong in the model. 

No they're not.  I tend to think models should know how to display 
themselves.  Otherwise, you wind up with poor view code like your 
earlier example and inappropriate coupling with the model's internals.

I'm not saying models should generate their own HTML formatting, but I 
don't think it's unreasonable to have them responsible for their own 
string representation.  Then the views can consume those strings.


> Now, if foo
> and bar were presenter instances, things would look different.
>

That's too simple an example to need a presenter.  Or, I think, a 
helper.

> Michael
> 
> --
> Michael Schuerig
> mailto:mich...@schuerig.de
> http://www.schuerig.de/michael/

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
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.

Reply via email to