views:

353

answers:

1

I'm trying to extend ActiveRecord with the custom validation method validate_as_email so i could use it like this:

class User < ActiveRecord::Base
  validates_as_email :email
end

I found description on how to extend ActiveRecord::Base class here: http://guides.rubyonrails.org/activerecord%5Fvalidations%5Fcallbacks.html It says you have to create a *.rb class under config/initializers/{myfile}.rb.

ActiveRecord::Base.class_eval do  
   def self.validates_as_email(attr_name)  
      validate is_email_fn(attr_name)
   end
end

What do I have to do next so I could use validates_as_email in my model and where should I put is_email_fn() function.

+4  A: 

hope this will help you http://marklunds.com/articles/one/312

webnuwan