I'd like to use the mail_to method in a model

Hi all

I’d like to use the mail_to method from the views within a model:

How can I include this module into my model?

Thanks
Josh

On Tue, Oct 13, 2009 at 6:14 PM, Joshua M.
[email protected] 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 M…
There’s no place like ~

On Oct 13, 2009, at 5:21 PM, Leonardo M. wrote:

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 M…
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 B. http://agileconsultingllc.com
[email protected]

Here’s how to use the mail_to helper in a view:

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001602

On Oct 13, 5:14 pm, Joshua M. [email protected]