Topic: Function in model to overwrite default database models

Probably a very simple question!

I have a field in my db called Phone - I don't want to do number_to_phone(@item.phone, :area_code => true) everytime, so I create a function in my model:

include ActionView::Helpers::NumberHelper
def phone
    number_to_phone(self.phone, :area_code => true)
end

This gives me "Stack level too deep".

How can I kill the recursion?  Sure I could do def formatted_phone - but that's kinda boring smile

Re: Function in model to overwrite default database models

Try:

def phone
    number_to_phone(self[:phone], :area_code => true)
end

This will be accessing the phone in a different way so there shouldn't be any recursion.

Railscasts - Free Ruby on Rails Screencasts

Re: Function in model to overwrite default database models

So easy!

Thanks!