On Oct 13, 2009, at 5:21 PM, Leonardo Mateo wrote:> On Tue, Oct 13, 2009 at 6:14 PM, Joshua Muheim
> <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:
>>
>> Hi all
>>
>> I''d like to use the mail_to method from the views within a
model:
>>
>> http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
>>
>> How can I include this module into my model?
>>
> Ok, besides the obvious question of "Why on earth would you do
that?",
> I think you can require the helper on your model, but seriously... why
> would you do that? It just feels wrong, you''re mixing UI within
your
> model.
>
> --
> Leonardo Mateo.
> There''s no place like ~
>
Well, I often (for example in an InvoiceItem model):
include ActionView::Helpers::NumberHelper#number_to_currency
def to_s
"%-40.40s %5d %14s %14s"%[self.description, self.units,
number_to_currency(self.unit_price),
number_to_currency(self.total)]
end
So as to not duplicate the number_to_currency functionality. But
that''s just a wee bit of the NumberHelper. You do know how to handle a
loaded Ruby feature like ''include'' don''t you? BTW,
it''s really just
include ActionView::Helpers::NumberHelper
because the # starts the comment. It''s really just a little hint and
just happens to look like the instance method convention of RDoc.
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org