Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

validates_acceptance_of validation failed #1812

Closed
ikonyshev opened this Issue · 4 comments

2 participants

Ivan Konyshev Durran Jordan
Ivan Konyshev

I got the following lines in model:

field :terms_of_service, type: Integer, default: 0
validates_acceptance_of :terms_of_service

Line from log:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"Na45gHSCacDjkndNY7rmjV8/t9cEDg+W45RnS8KfcIs=", 
"user"=>{"email"=>"*****@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]",
 "first_name"=>"I", "last_name"=>"K", "phone"=>"**********", "terms_of_service"=>"1"},
 "commit"=>"Зарегистрироваться"}

But validation of terms_of_service has been failed

Durran Jordan
Owner

I'm not on a computer right now so I cannot confirm yet, but can you show me the call you're making that gets the error and user.errors? Thanks!

Durran Jordan
Owner

And the mongoid and rails versions as well?

Ivan Konyshev

Rails 3.2.1, mongoid 2.4.5
Also I use devise in this model, but all other validations work fine


1.9.3p0 :001 > user = User.new(first_name: 'I', last_name: 'K', terms_of_service: 1, 
email: 'xxxxxx@gmail.com', password: 'qwerty', password_confirmation: 'qwerty', phone: 'xxxxxxxxxx')
 => #<User _id: 4f5b89dd6faefd4697000001, _type: nil, email: "xxxxxx@gmail.com", encrypted_password: 
"$2a$10$9TXwfxOMdLcIXu0McdZ6BOn9QRKBjFj/mwrFE1Ll4voFzy2Mon15S", remember_created_at: nil, 
reset_password_token: nil, reset_password_sent_at: nil, sign_in_count: 0, current_sign_in_at: nil, 
last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, first_name: "I", last_name: "K", 
phone: "xxxxxxxxxx", gender: nil, image: nil, urls: nil, vk_uid: nil, discount: 0, terms_of_service: 1> 
1.9.3p0 :002 > user.valid?
 => false 
1.9.3p0 :003 > user.errors => #<ActiveModel::Errors:0x00000004320d58 @base=#<User _id: 4f5b89dd6faefd4697000001, 
_type: nil, email: "xxxxxx@gmail.com", encrypted_password: "$2a$10$9TXwfxOMdLcIXu0McdZ6BOn9QRKBjFj/mwrFE1Ll4voFzy2Mon15S", 
remember_created_at: nil, reset_password_token: nil, reset_password_sent_at: nil, sign_in_count: 0,
 current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, first_name: "I", 
last_name: "K", phone: "xxxxxxxxxx", gender: nil, image: nil, urls: nil, vk_uid: nil, discount: 0, terms_of_service: 1>, 
@messages={:terms_of_service=>["THIS IS ACCEPTANCE VALIDATION MESSAGE Для регистрации необходимо 
ознакомиться с условиями использования сервиса и принять их"]}> 

Durran Jordan
Owner

Ah - I see now what happened. The terms of service field is defined as an integer, where the default acceptance in Active Model is a String:

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations/acceptance.rb#L7

You'll need to change your validation accept to be an int:

validates_acceptance_of :terms_of_service, :accept => 1
Durran Jordan durran closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.