Reputation: 17412
I wrote this custom validator:
class SecureTokenValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
Rails.logger.debug("validate_each options: #{options.inspect}")
end
end
And here the model:
class User < ActiveRecord::Base
has_secure_password
attr_accessor :token
validates_length_of :password, minimum: 6
validates_uniqueness_of :email
validates :token, secure_token: {attributes: %w(salutation first_name last_name) }
end
But the options are not passed to validator, here the entry from the log:
validate_each options: {}
Why? I'm using Rails 3.1.1 on Ruby 1.9.2p290
Upvotes: 3
Views: 1674
Reputation: 17412
I had to choose a different name than attributes
for my option. Now it's called attribute_order
and works fine.
Upvotes: 2