How To Implement Devise Gem In Rails Application

How To Implement Devise Gem In Rails Application

18 May 2021
How To Implement Devise Gem In Rails Application


What is Devise Gem?

Devise Gem is a flexible user authentication used in Ruby on Rails-based applications. In this blog, we will understand how to set up a Devise in the web app, for the user to add user registration, login, and logout.


The need for migration:

Devise is the foundation gem for Ruby on Rails authentication. Devise is utilized to create a user for easy login and out from the application. The migration process is simple as devise takes care of all the controllers necessary for user creation (users_controller) and for user sessions (users_sessions_controller)



  • Ruby on Rails
  • MVC Framework


Let's understand the required steps to apply Devise in Rails application.


Step 1: Create a new Rails application (rails new devise_gem)


Step 2: Add Devise to the Gem file.


Step 3: Run bundle installs on the terminal.


Step 4:  Run the below command on the terminal.


           $ rails generate devise:install.          


Step 5: Certain instructions will be displayed on the user console window.


Step 6:  Defined root_url to *something* in the config/routes.rb.


Step 7:  Copy Devise views (for customization) to the app by running the command.


           $ rails g devise:views


Step 8: Generate a model or devise model.


      $ rails generate devise User


Step 9: Before migrating the database, check the migration file.


Step 10: Add columns in the devise model.


 $ rails generate migration add_name_to_user name:string surname:string


Step 11: With the following command start the database migration


          $ rails db:create db:migrate db:seed


Step 12: After the database migration is complete, check the sign-up form on the application.


          $ rails server 


Step 13: Go to any internet browser on the computer and enter the address: http://localhost:3000/users/sign_up.


Step 14: The sign-up page will look like this.




Leave a comment: