Add Devise to Your Rails Application

  • This blog picks from the end of (section 8.1 Deleting Associated
    Object)[guides.rubyonrails.org/getting_started.html] We are going to be
    replacing the following section, section 9 “Security with” by implmenting
    Devise. Devise provides thorough decoumentation so for more detail please
    visit (Devise)[https://github.com/plataformatec/devise] We are going to be
    replacing the following section, section 9 “Security with” by implmenting
    Devise. Devise provides thorough decoumentation so for more detail please
    visit (Devise)[https://github.com/plataformatec/devise].

  • First we want to get the lastest version of Devise and we can do this by
    visiting (RubyGems)[https://rubygems.org/]. Type in “devise” in the search
    windown. The latest version at the time of this writing was as show below

  • Add devise gem

    1
    gem 'devise', '~> 4.3'
  • Run the following command to install the Devise Gem

1
$ bundle
  • Next install Devise by running the following command
1
$ rails g devise:install
  • Next create the User model
1
$ rails g devise user
  • Run the migration to create the User table
1
$ rails db:migrate
  • If you’re using Rails 4x or less use $ rake instead of $ rails,
    leave out the $ sign.

_ Next we want to create the views and for this please see my previous blog and
take it from there. In this blog (Implementing Devise Bootstrap
Views)[https://www.zambezi.io/articles/devise-bootstrap-views], I go through how
we can use the devise-bootstrap-views to generate clean, beautiful views.