You can also create writers for your fields and do the cleanup there:

class Phone < ActiveRecord::Base
 def number=(num)
       write_attribute('number', num.gsub(/\D/, ''))
   end
end

which would strip all non digits from a phone number when it's set. Then, to double-make-sure you can add a validates_format_of to check it again.

Tom

Patrick Crowley wrote:
So I'm working on a site where users submit links that have certain properties.

I'm using a couple of the standard validate helpers (presence_of, uniqueness_of, etc.) but there's additional content shaping I'd like to do.

So far, I've stuffed these additional content filters into my model's validate method. Things like stripping white space, using pattern matching to reformat malformed links, etc.

Just curious... is this common practice? I thought about putting this code in my controller, but it seems more appropriate to continually validate the link format, regardless of where content is entered into the system.

-- Patrick

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby



--
Tom Werner
Helmets to Hardhats
Software Developer
[EMAIL PROTECTED]
www.helmetstohardhats.org

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to