This project is archived and is in readonly mode.

#5501 ✓invalid
Alexey Poimtsev

Validations of acceptance not working

Reported by Alexey Poimtsev | August 30th, 2010 @ 08:33 PM

Hi,
i have model like

class User < ActiveRecord::Base
  attr_accessible :username, :email, :password, :password_confirmation, :remember_me
  attr_accessor :terms

  validates :username,
            :presence => true,
            :format => { :with => /\A[a-z0-9\-]+\z/i },
            :uniqueness => true,
            :length => 3..20

  validates :email,
            :presence => true,
            :format => { :with => /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i },
            :uniqueness => true

  validates :password,
            :presence => true,
            :confirmation => true,
            :length => 6..20

  validates :terms,
            :acceptance => true

end

Everything is ok, but validation of :terms does not working.

Comments and changes to this ticket

  • Alexey Poimtsev

    Alexey Poimtsev August 30th, 2010 @ 08:34 PM

    • Tag changed from validates_acceptance_of rails3, validations to validations
  • Raony vieira

    Raony vieira August 30th, 2010 @ 08:58 PM

    I've go a bit similar problem, my is not validating my collection_select.
    Does someone have a clue about that?
    cheers

  • Neeraj Singh

    Neeraj Singh August 30th, 2010 @ 10:04 PM

    • Importance changed from “” to “Low”

    by default nil is allowed. You need to do

    validates :terms,
                :acceptance => true, :allow_nil => false
    

    I do agree that :allow_nil should be 'false' be default. That would make more sense. I will talk to rails core team member and if agree will change the default value.

  • José Valim

    José Valim August 31st, 2010 @ 04:56 AM

    • State changed from “new” to “invalid”

    :allow_nil should be true. Because it allows you to create users through the console/tests without having to specify :terms => true, so it is a convenience.

    This won't be a problem in your views, because once you do: f.checkbox :terms, it will never be nil because it would already default to false.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages