Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7891257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:34:21+00:00 2026-06-03T06:34:21+00:00

When creating a user, I’m checking if the terms of usage were accepted like

  • 0

When creating a user, I’m checking if the terms of usage were accepted like so:

# user.rb
class User < ActiveRecord::Base
  validates_acceptance_of :terms, :message => :terms_not_accepted, :on => :create
  attr_accessible :terms, :on => :create # required because I completely disable mass-assignment in an initializer
end

I have the following fields in my form view:

<label class="checkbox"><%= f.check_box :terms %><span><%=t "users.form.label.terms" %></span></label>

So far, everything works as expected. If the user does not accept the terms, there will be an error message. However, if I just remove the checkbox (and corresponding hidden field generated by the view helper) from the HTML page using e.g. Chrome developer tools, the user will be created!

I can reproduce this in the console:

irb(main):001:0> u = User.new # => #<User ...>
irb(main):002:0> u.terms # => nil
irb(main):003:0> u.save! # => other validations fail, but terms check succeeds!
irb(main):004:0> u.terms = false # => false
irb(main):005:0> u.save! # => terms validation fails as expected

One more info: validates :terms, :acceptance => true yields the same result

I know that I can initialize the terms attribute with false in an after_initialize callback, but I do not want to do that since the validator should be able to handle the nil case. So is this a bug in rails or am I doing something wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:34:22+00:00Added an answer on June 3, 2026 at 6:34 am

    If you’d like to make sure that the user accepts terms, then you can set allow_nil to false

    http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000082

    :allow_nil - Skip validation if attribute is nil (default is true).
    

    So change to

    validates_acceptance_of :terms, :on => :create, :allow_nil => false, :message => :terms_not_accepted,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently creating a user interface using WPF and would like to display a
I've created my own signup form and creating the user using the Membership class.
I want to create a hash that combines the creating user's user_id + the
I'm creating a user approval interface leveraging the .Net Membership class. I have a
I'm creating user control in MVC3 application. My view model looks like that: public
I would like to know why we use XML for the creating user interface
I am creating a user input at one of the events: var throwConnectBox =
We are creating a user interface that functions on a wide variety of platforms
I am creating an user registration form using jsp,in which there is an option
Given that you're creating a User Control in WPF that will be displayed on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.