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_validations_callbacks.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.

xpepermint
  • 35,055
  • 30
  • 109
  • 163

1 Answers1

4

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

webnuwan
  • 539
  • 1
  • 4
  • 6