# I'd like to use the mail\_to method in a model

**URL:** <https://www.ruby-forum.com/t/id-like-to-use-the-mail-to-method-in-a-model/177236>\
**Category:** Rails\
**Created:** [October 13, 2009, 11:14pm UTC](https://www.ruby-forum.com/t/id-like-to-use-the-mail-to-method-in-a-model/177236 "2009-10-13T23:14:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [October 13, 2009, 11:14pm UTC](https://www.ruby-forum.com/t/id-like-to-use-the-mail-to-method-in-a-model/177236/1 "2009-10-13T23:14:10Z")

</div>

Hi all

I’d like to use the mail\_to method from the views within a model:

> **[ActionView::Helpers::UrlHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html)**
>
> Provides a set of methods for making links and getting URLs that depend on the routing subsystem (see ActionDispatch::Routing).

How can I include this module into my model?

Thanks  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [October 13, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/id-like-to-use-the-mail-to-method-in-a-model/177236/2 "2009-10-13T23:23:36Z")

</div>

On Tue, Oct 13, 2009 at 6:14 PM, Joshua M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all
> 
> I’d like to use the mail\_to method from the views within a model:
> 
> [ActionView::Helpers::UrlHelper](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 ~

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [October 14, 2009, 12:05am UTC](https://www.ruby-forum.com/t/id-like-to-use-the-mail-to-method-in-a-model/177236/3 "2009-10-14T00:05:46Z")

</div>

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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [October 14, 2009, 2:17am UTC](https://www.ruby-forum.com/t/id-like-to-use-the-mail-to-method-in-a-model/177236/4 "2009-10-14T02:17:30Z")

</div>

Here’s how to use the mail\_to helper in a view:

> **[ActionView::Helpers::UrlHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001602)**
>
> Provides a set of methods for making links and getting URLs that depend on the routing subsystem (see ActionDispatch::Routing).

On Oct 13, 5:14 pm, Joshua M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
