User Authentication in Rails

Download ruby-on-rails eBook

Introduction

Devise is a very powerful gem, it allows you to sign up, sign in and sign out options just after installing. Moreover user can add authentications and restrictions to its applications. Devise also come with its own views, if user wants to use. A user can also customize sign up and sign in forms according to its need and requirement. It should be noted that Devise recommends that you implement your own login if you're new to rails.

Remarks

At the time of generating devise configs using rails generate devise:install, devise will list out bunch of instructions on the terminal to follow.

If you already have a USER model, running this command rails generate devise USER will append necessary columns to your existing USER model.

Use this helper method before_action :authenticate_user! at the top of your controller to check whether user is logged-in or not. if not then they will be redirected to sign-in page.

Related Examples

Stats

259 Contributors: 10
Tuesday, January 17, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook