
When it comes to authentication, most people in the Rails world use Devise. Let's install it and see how it works.
Installing Devise requires some effort on your part, which includes:
bundle add devise
Next, run the installer, which will add the initializer as well as the localization bits:
rails generate devise:install
You can find the initializer (with config settings) inside config/initializers/devise.rb
. Our next task is to associate (or create) the model that Devise will work with:
rails generate devise User
If you don't have a User
model, Devise will create one for you. Otherwise, it will add stuff to your existing model. Have a look and see the settings in there, and also make sure your migration aligns with whatever you choose (trackable
, confirmable
, etc).
Finally, we need to output the views so we can tweak them:
rails g devise:views
Make sure you run your migrations, and off you go!