Last active
December 16, 2015 21:09
-
-
Save tatat/5497457 to your computer and use it in GitHub Desktop.
Rails4(くらい)で has_secure_password のバリデーションをスキップしたり
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_secure_password validations: false | |
validates :password, | |
presence: {if: :password_required?, on: :create}, | |
confirmation: {if: :password_required?} | |
validates :password_confirmation, | |
presence: {if: :password_present?} | |
before_create { | |
raise 'Password digest missing on new record' if | |
password_required? and password_digest.blank? | |
} | |
def password_present? | |
password.present? | |
end | |
def password_required? | |
raise 'ここに条件が来ます。' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment