Using helper methods in models?

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.

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 !!Es gratis!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs