How to use Devise gem with Ruby on Rails 7

Nejdet Kadir Bektaş
1 min readDec 24, 2021

--

Ruby On Rails 7

Devise gem is a flexible authentication for Ruby on Rails based application, and it is one of the most popular rails gem with more than 113 million downloads.

In this blog will go throw how to setup devise in your web application with Rails 7.

Setup

$ rails new rails7-devise-example
$ cd rails7-devise-example

Add deviseto the Gemfile.

gem "devise", github: "heartcombo/devise", branch: "main"

Run bundle to install them.

$ bundle install

Setup Devise

Install devise. This generates a number of files.

$ rails g devise:install
$ rails g devise:views

Now create a model and migration with devise, and migrate to generate tables.

$ rails g devise User
$ rails db:create
$ rails db:migrate

Update the generated devise initializer with the following codes. You can find my custom code with #! desccomment block.

Create a new devise controller, /controllers/users/devise_controller.rb.

Start the app

Start your rails server.

$ rails server

--

--