DEV Community


Posted on

Devise Gem

In my previous post, I mentioned the Devise gem, which handles the user authentication process in Rails. It simplifies the process in several ways: it generates the necessary controllers for user login and sessions, creates forms for user sign up/log in, and handles the encryption process with bcrypt, eliminating the need to salt and hash passwords yourself. The Devise gem also provides compatibility with other user authentication methods like OAuth, so the user would have the option to log in through a third party. This gem is great for streamlining the user authentication process and ensuring app security.

In this post, I want to go through set up with the gem!

Setting up:
Add gem devise to your Gemfile and run bundle install

Run rails g devise:install

Creating the User Model
Run rails g devise user and rake db:migrate

Voila! This gem will generate the controller for user log in.

To generate views run rails g devise:views

To work with Devise routes, add to routes.rb: devise_for :MODELNAME where MODELNAME is the name of the model you want to create the route for.

Discussion (0)