The Devise Gem makes it really easy to create a full authentication app with Ruby on Rails. In the video below, I will walk you through setting up and installing the Devise Gem on your rails app. Below the video are all the commands and code that I used to create the application.
First off, we need to create our new rails application.
$ rails new devise
$ cd devise
$ mate .
Inside of your text editor, you'll want to add the devise to your 'Gemfile', which is located in the application root directory. Add the following line to the 'Gemfile':
gem 'devise'
Back in your terminal window:
$ bundle install
$ rails generate devise:install
$ rails generate devise user
$ rake db:migrate
$ rails g controller home
$ rails g controller dashboard
Inside of your '/app/controllers/home_controller.rb' file, add the following:
def index
if user_signed_in?
redirect_to :controller=>'dashboard', :action => 'index'
end
end
Inside of your '/app/controllers/dashboard.rb' file, add the following:
before_filter :authenticate_user!
def index
end
Inside of your '/app/views/home/' and '/app/views/dashboard/' directories create a new file called 'index.html.erb' and add the following code into each file:
Welcome to our Website
Welcome to your dashboard
Now, inside of your '/app/views/layouts/application.html.erb' add the following code below the opening 'body' tag: