Techie February 2022
Definition
Devise is an authentication gem for rails applications. It allows you to create users that can log in and out of your application.
1. Add devise gem
a). Open up your Gemfile and add this line
and run:
Or:
b).Run:
2. Set up devise in your app
3. Configure Devise
Ensure you have defined default url options in your environments files. Open up config/environments/development.rb and add this line before the ‘end’ keyword:
4. Add the notification alert
Open up app/views/layouts/application.html.erb and add the following right above <%= yield %> :
5. Setup the User model
6. Add sign-up and login links.
In order to do that go to, app/views/layouts/application.html.erb and add:
7. Redirect the User
Finally, force the user to redirect to the login page if the user was not logged in. Open up app/controllers/application_controller.rb and add the following after the protect_from_forgery with: :exception. :
Make sure your rails server is running, open http://localhost:3000/users/sign_up and create your user account.
8. Customize Devise Views
You can style the devise views according to your preference. Run the command below to generate the views and then provide css style for them:
Thanks for reading, see you in the next one!