I have an validator EmailValidator and class User:
class EmailValidator < ActiveModel::Validator
def validate(record)
record.errors[:base] << "error" unless record.email.scan("@")
end
class User < ActiveRecord::Base
validates_with EmailValidator
end
If I put EmailValidator definition in separate file in lib/ directory, or in user.rb after User class definition I get an error:
/usr/lib/ruby/gems/svn/gems/rspec-core-2.0.0.beta.16/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant User::EmailValidator (NameError)
But if I put EmailValidator definition before User definition in user.rb like in example above it is ok.
In what place I should put EmailValidator?