Ruby on Rails / Devise - Bypassing custom validation option in model when resetting password

前端 未结 3 1063
名媛妹妹
名媛妹妹 2021-02-06 05:00

In my project, I altered the registration form in Devise to add an :agree option via an accessor (user must accept terms of service to register, etc). If they don\'t agree, it d

3条回答
  •  执笔经年
    2021-02-06 05:56

    So, you need to validate the acceptance of terms when the record is created?

    class User < ActiveRecord::Base
      validates :agree, :acceptance => true, :on => :create
    end
    

    :on => :create will only perform that validation when the record is being created—much like Brandon's answer, but without redundant code.

    This will also obviate the need for your controllers to worry about if a user is signed in or not.

提交回复
热议问题