If we have to don our wizarding hat and take out our crystal balls, we would still be harping that Ruby on Rails is going to be hot in 2026 too! 2026 is also going to bring in only 24 hours a day (how we wish, we could stretch the time) and time would still spell money for businesspeople. When time is money, anything which can save time is gold! And that’s where Ruby on Rails come in picture. What could take other programming languages months to complete, takes only weeks, sometimes just days for Ruby on Rails. Shaping ideas into applications was never so easy. With Ruby on Rails, agility is the norm and convention over configuration the benchmark. And what make Ruby on Rails more powerful are the bunch of pre-packaged, categorized, reusable codes, named as gems. With gems, Rails is a super power to behold. One of the most popular gems is called as Devise Gems, which is a complete authentication package. Read on to know more about Devise gem.
Introducing Devise for Ruby on Rails 8
Devise is a widely used authentication library for Ruby on Rails 8 applications, built on top of Warden, a Rack-based authentication framework.
Warden manages user sessions by securely validating the identity of authenticated users. It also ensures that unauthenticated users are restricted from accessing protected routes and resources within a Rails application.
Since Warden operates strictly at the Rack level, it does not provide Rails-specific features such as controllers, views, helpers, or configuration generators required for a complete authentication system. Devise bridges this gap by adding these Rails integrations, making it easier to implement a robust and production-ready authentication solution in Rails 8.
A major advantage of Devise is its modular architecture. It includes around ten authentication modules that allow you to customize how authentication behaves in your application. You can enable only the modules you need—such as Registerable, Omniauthable, Trackable, and others—keeping your authentication setup clean and flexible.
With this understanding, we can now begin building our Tasks application and set up Devise in a Rails 8 environment.
What is ‘Devise’ Gem?
- Devise is a powerful & flexible authentication solution for Rails.
- It is completely based on MVC structure.
- It allows to have multiple models signed in at the same time.
Different Modules of Devise
Devise is composed of 10 important modules.
- Database Authenticatable: It encrypts and stocks passwords in the database so that the validation could be done for the authenticity of a user at the time of signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
- Omniauthable: Add OmniAuth support i.e. possible to set up a login with OmniAuth.
- Confirmable: Sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
- Recoverable: Resets the user password and sends reset instructions.
- Registerable: Handles registration process by signing up users also allowing them to edit and destroy their account.
- Rememberable: As the name suggests, it helps in managing, generating and clearing a token for remembering the user through saved cookies.
- Trackable: Tracks sign in count, timestamps and IP address.
- Timeoutable: Expires sessions that have not been active in a specified period of time.
- Validatable: Provides validations of email and password. It’s optional and can be customized, so you’re able to define your own validations.
- Lockable: It helps in locking an account after a specific number of failed sign-in attempts. The account could be unlocked via email or after specific time period.
Install Devise, Create Model, View & Configure
- Create your rails app
- Add gem ‘devise’ to your Gemfile.
- Run bundle install in your command line.
- Execute rails generate devise:install in your command line.
- Execute rails generate devise <Model Name> in your command line to create model
rails generate devise User
class User < ApplicationRecord # Include default Devise modules. # Other available modules are: # :confirmable, :lockable, :timeoutable, and :omniauthable
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable
end
- If you want, you can modify your migration file for user. Then run rake db:migrate
- Execute rails generate devise:views in your command line to create views
- you need to set up the default URL options for the Devise mailer in each environment. Ex- configuration for config/environments/development.rb: config.action_mailer.default_url_options = { host: ‘localhost’, port: 3000 }
You can customize models, controllers and views as per requirement. Please follow the github documents for more details.
Some Controller Filters and Helpers
- To set up a controller with user authentication before_action :authenticate_user!
- To verify if a user is signed in or not => user_signed_in?
- For the current signed-in user => current_user
- access the session for this scope: => user_session
- You can also override after_sign_in_path_for and after_sign_out_path_for to customize your redirect paths.
You can integrate ‘activeadmin’ gem, ‘devise_invitable’ gem with devises.
When it comes to time saving, nothing beats Ruby on Rails. If you have an idea and would like to get it implemented, the best bet for you would be to go for Ruby on Rails. RailsCarma has been implementing Ruby on Rails from its nascent stages for development, training, deploying and contributing back to the Rails Community and provide best Ruby on Rails development services. RailsCarma provide end to end Ruby on Rails services including, consulting, architecture, building, management and extension to companies around the globe. You can also hire Ruby on Rails developers with an easy to hire process. Contact Us to know more.