Authentication using Devise

suggest change

Add the gem to the Gemfile:

gem 'devise'

Run bundle install, then rails generate devise:install to create the initializer.

Set the default URL options for the Devise mailer in each environment. In config/environments/development.rb:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

In config/environments/production.rb:

config.action_mailer.default_url_options = { host: 'your-site-url' }

Create the model with rails generate devise User. User is the class that will be authenticated.

Then run rails db:migrate.

Custom views

If you need to configure your views, you can use the rails generate devise:views generator that will copy all views to your application. Then you can edit them as desired.

If you have more than one Devise model in your application (for example User and Admin), you will notice that Devise uses the same views for all models. Devise offers an easy way to customize views. Set config.scoped_views = true inside the config/initializers/devise.rb file.

You can also use the generator to create scoped views: rails generate devise:views users

To generate only some views, such as registerable and confirmable, pass -v: rails generate devise:views -v registrations confirmations.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents