Given a user mode开发者_开发知识库l 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 = ['dont@validate.me'].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?
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 !['dont@validate.me'].include?(instance_email)
# write here your validation logic
end
end
end
精彩评论