How to skip has_secure_password validations

后端 未结 3 528
忘掉有多难
忘掉有多难 2020-12-09 03:22

In my app, only admins can create new User records. The user is emailed an activation link where they set their password.

I\'d like to use the has_secure_passord met

3条回答
  •  余生分开走
    2020-12-09 04:15

    Since 4.X versions of rails, has_secure_password takes an option :validations. If you set it to false, it will not run validations.

    The 3.X version of the gem does not support this parameter. However you can backport the activemodel/lib/active_model/secure_password.rb from latest 4.0.XRC code which supports this argument.

    So with that, your code will look like this:

    class User < ActiveRecord::Base
      has_secure_password :validations => false
      ...
    end
    

提交回复
热议问题