So first we will create rails project and setup device
create a rails application
rails new devise_example
now add devise to gem list
you can find a file named ‘Gemfile’ at the root of rails project
Then run bundle install
Next, you need to run the generator:
rails generate devise:install
Now on console you can find few instructions just follow it.
Generate devise model
rails generate devise MODEL
Then run rake db:migrate
For more details go to: Devise Gem
Authentication token is used to authenticate a user with a unique token, So Before we proceed with the logic first we need to add auth_token field to a Devise model
Hence,
rails g migration add_authentication_token_to_users
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :auth_token, :string, default: ""
add_index :users, :auth_token, unique: true
end
end
Then run rake db:migrate
Now we are all set to do authentication using auth_token