ruby on rails - Validates acceptance always fails -
ruby on rails - Validates acceptance always fails -
no other answers found on issue helped me.
i have terms , conditions box , want validate if it's checked on creation.
in model:
validates :terms_and_conditions, :on => :create, acceptance: true, :allow_nil => false
in view:
<%= f.check_box(:terms_and_conditions )%>
it fails, no matter if check_box
checked or not. think never sets field , problem in view, can't find it.
log when submitting form.
processing users::registrationscontroller#create html parameters: {"utf8"=>"✓", "authenticity_token"=>"xnnmgtwsv4hkj0rrlzeoq+aitlj9sc9+cat1sy0bjhc=", "user"=>{"email"=>"sdasdr@gmail.com", "password"=>"[filtered]", "password_confirmation"=>"[filtered]", "name"=>"", "surname"=>"", "country_id"=>"", "language"=>"", "description"=>"", "register_as_company"=>"1", "terms_and_conditions"=>"1"}, "commit"=>"sign up"} unpermitted parameters: name, surname, country_id, language, description, register_as_company, terms_and_conditions [1m[35m (0.1ms)[0m begin transaction [1m[36muser exists (0.3ms)[0m [1mselect 1 1 "users" "users"."email" = 'sdasdr@gmail.com' limit 1[0m [1m[35m (0.1ms)[0m rollback transaction [1m[36mcountry load (0.2ms)[0m [1mselect "countries".* "countries"[0m rendered devise/registrations/new.html.erb within layouts/application (6.1ms) rendered layouts/_auth_widget.html.erb (1.1ms) completed 200 ok in 127ms (views: 22.8ms | activerecord: 0.7ms)
you have not permitted terms_and_conditions
attribute saved in database. if notice server logs closely,
unpermitted parameters: name, surname, country_id, language, description, register_as_company, terms_and_conditions
there multiple attributes not permitted of them not getting saved in database. terms_and_conditions
goes nil
, results in error value submitted via form ignored (because of unpermitted status).
this related rails 4 strong parameters concept wherein attributes saved in database whitelisted/ permitted.
checkout info on strong parameters
also, per server log noticed these attributes part of user
model devise
model. permitting attributes devise can done in different ways, can refer so question: rails devise simple form not saving fields this.
ruby-on-rails forms ruby-on-rails-4 devise
Comments
Post a Comment