Created
April 11, 2016 00:46
-
-
Save hugodias/4482bdfffaf354a7f7e87cc1ab101ab4 to your computer and use it in GitHub Desktop.
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 | |
| devise :database_authenticatable, :registerable, | |
| :recoverable, :rememberable, :trackable, :validatable | |
| before_save :ensure_authentication_token | |
| def ensure_authentication_token | |
| if authentication_token.blank? | |
| self.authentication_token = generate_authentication_token | |
| end | |
| end | |
| private | |
| def generate_authentication_token | |
| loop do | |
| token = Devise.friendly_token | |
| break token unless User.where(authentication_token: token).first | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment