0
0
Ruby on Railsframework~30 mins

Devise gem overview in Ruby on Rails - Mini Project: Build & Apply

Choose your learning style9 modes available
Devise Gem Overview in Rails
📖 Scenario: You are building a simple Rails application that needs user authentication. To make this easier, you will use the Devise gem, which helps add sign up, login, and logout features quickly.
🎯 Goal: Learn how to set up the Devise gem step-by-step in a Rails app. You will create the initial user model, configure Devise, add authentication routes, and complete the setup to have a working user login system.
📋 What You'll Learn
Create a new Rails app with Devise installed
Generate a User model with Devise modules
Configure Devise settings in the app
Add Devise routes to the application
Complete the setup to enable user authentication
💡 Why This Matters
🌍 Real World
Most web apps need user accounts and login features. Devise makes adding these features fast and secure.
💼 Career
Knowing how to use Devise is a key skill for Rails developers working on real-world applications with user authentication.
Progress0 / 4 steps
1
Install Devise and Generate User Model
Add the devise gem to your Gemfile and run bundle install. Then run rails generate devise:install to set up Devise. Finally, generate a User model with Devise by running rails generate devise User.
Ruby on Rails
Need a hint?

Start by adding gem 'devise' to your Gemfile. Then run the commands to install and generate the User model.

2
Configure Devise Settings
Open the config/initializers/devise.rb file and set the config.mailer_sender to "please-change-me@example.com". Also, ensure you have run rails db:migrate to create the users table.
Ruby on Rails
Need a hint?

Devise needs a mailer sender email set. Also, run migrations to create the users table.

3
Add Devise Routes to Your Application
In the config/routes.rb file, add devise_for :users to create all the routes needed for user authentication.
Ruby on Rails
Need a hint?

This line adds all the routes Devise needs for user sign up, login, logout, and more.

4
Complete Setup and Test Authentication
Add a root route in config/routes.rb pointing to home#index. Create a simple HomeController with an index action and view. Use before_action :authenticate_user! in the controller to require login. This completes the Devise setup for user authentication.
Ruby on Rails
Need a hint?

Set a root page and protect it so only logged-in users can see it.