Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nahurst/1454190 to your computer and use it in GitHub Desktop.
Save nahurst/1454190 to your computer and use it in GitHub Desktop.
Add TokenAuthenticatable to an existing user model for devise
# remember to add "devise :token_authenticatable" to user.rb
# and uncomment "config.token_authentication_key = :auth_token" from devise.rb
class AddTokenAuthenticatableToUsers < ActiveRecord::Migration
def self.up
change_table(:users) do |t|
t.token_authenticatable
end
User.reset_column_information
User.all.each do |user|
user.ensure_authentication_token
user.save
end
end
def self.down
remove_column :users, :authentication_token
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment