Last active
September 6, 2016 16:38
-
-
Save acro5piano/7620f6e394ef89727d1347e91f46ca2f to your computer and use it in GitHub Desktop.
has_secure_passwordでauthenticateメソッドが追加される仕組み ref: http://qiita.com/acro5piano/items/416c08a808c850e0477e
This file contains hidden or 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
| require_relative './secure_password' | |
| class ActiveRecord | |
| extend SecurePassword | |
| end |
This file contains hidden or 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 | |
| end | |
| user = User.new | |
| user.authenticate('password') |
This file contains hidden or 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
| require_relative './user.rb' | |
| user = User.new | |
| puts user.authenticate | |
| #=> true |
This file contains hidden or 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 | |
| has_secure_password | |
| def test | |
| has_secure_password | |
| end | |
| end | |
| user = User.new | |
| puts user.authenticate | |
| puts user.test | |
| # => undefined method `has_secure_password' | |
| # for #<User:0x0055b91a9f0280> NoMethodError |
This file contains hidden or 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
| module SecurePassword | |
| def has_secure_password | |
| include SecurePassword::InstanceMethodsOnActivation | |
| end | |
| module InstanceMethodsOnActivation | |
| def authenticate | |
| true | |
| end | |
| end | |
| end |
This file contains hidden or 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
| require_relative './active_record' | |
| class User < ActiveRecord | |
| has_secure_password | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment