views:

58

answers:

1

Given a user model something along the lines of:

class User < ActiveRecord::Base

  acts_as_authentic do |config|
    config.validate_email_field = true
  end

end

I would like to be able to modify "true" to be specific to the user that is signing up. I would like to be able to do something like:

class User < ActiveRecord::Base

  acts_as_authentic do |config|
    config.validate_email_field = ['[email protected]'].include?(instance_email)
  end

end

but instance_email isn't available there. Do you have to override a method on the user model in order to access this variable? How can this be done?

+3  A: 

You can't because the Authlogic block is evaluated when the class is loaded and it has no instance context.

You need to write your own validator.

class User < ...

  validate :validate_email

  ...

  def validate_email
    if !['[email protected]'].include?(instance_email)
      # write here your validation logic
    end
  end 

end
Simone Carletti