Reputation: 2209
I am trying various options for the past three hours to make a "terms and conditions" checkbox working
Here is my code /models/user.rb
class User < ActiveRecord::Base
#validates :terms, acceptance: { accept: true } , :on => :create
validates_acceptance_of :terms, :allow_nil => false, :accept => true, :on => :create
end
this is what I am always getting
I added this to allow params
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
# for allowing terms in signup
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:terms])
end
end
Upvotes: 0
Views: 204
Reputation: 3742
You're passing 1
as a checkbox value. It's a default for the validator. So all you need is to get rid of :accept => true
option.
The true
one is used only in case of validating boolean database field. As I understand you don't have such a column in users table and only want to referer to the HTML checkbox.
Upvotes: 1