tags:

views:

17

answers:

1

I'd like to process the info in my form params before they enter the database, I just want to know what the optimal method is to do this.

For example, for my users model, should I add a method to each expected param, for example:

def first_name=(name)
  self.first_name = name.capitalize.strip
end

Or should I modify the form params in another way?

+1  A: 

Your approach will probably result in a stack overflow. You are calling the first_name= function recursively as every time you set self.first_name it is calling first_name=

The correct way to do this is as follows :-

def first_name=(name)
  write_attribute( :name, name.capitalize.strip)
end
Steve Weet
Thanks so much Steve, I appreciate it :)
Kevin