# Using helper methods in models?

**URL:** <https://www.ruby-forum.com/t/using-helper-methods-in-models/88720>\
**Category:** Rails\
**Created:** [March 13, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/using-helper-methods-in-models/88720 "2007-03-13T20:00:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [March 13, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/using-helper-methods-in-models/88720/1 "2007-03-13T20:00:48Z")

</div>

In my models I define the to\_s method so I can just do this in my views:

“#{@some\_model}”

The problem is when I want to format the output of attributes in that  
method. For example I want to format the attribute price to currency.  
There is a nice helper method called number\_to\_currency. How can I use  
this in my to\_s method in my model?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [March 14, 2007, 11:02am UTC](https://www.ruby-forum.com/t/using-helper-methods-in-models/88720/2 "2007-03-14T11:02:08Z")

</div>

> The problem is when I want to format the output of attributes in that  
> method. For example I want to format the attribute price to currency.  
> There is a nice helper method called number\_to\_currency. How can I use  
> this in my to\_s method in my model?

Helpers are just modules… I’d say you can include them as you would  
with any other. Only problem would be if any of your helper methods  
relies on the classes that are under Controllers’ hierarchy tree. If  
not, everything should be fine.

regards,

javier ramirez

## –

Estamos de estreno… si necesitas llevar el control de tus gastos  
visita [http://www.gastosgem.com](http://www.gastosgem.com) !!Es gratis!!
