-
rails new
rails new appname
-
Create a “home” controller and a “home/index” page
rails generate controller home index --no-controller-specs --skip-stylesheets --skip-javascripts
- –skip-stylesheets –skip-javascripts to avoid cluttering our application with stylesheet and JavaScript files we don’t need.
-
Set the default route to home/index in config/routes.rb
root 'home#index'
-
Set the time zone <../config/application.rb>
rake -D time rake time:zones:us config.time_zone = 'Pacific Time (US & Canada)'
-
Enable `devise` gem in Gemfile
gem 'devise', '~> 3.0.0.rc' # Wed May 8 18:03:54 PDT 2013, Rails 4.0.0.rc1
-
Run the Devise gem install generator
rails generate devise:install
-
Generate a User Model and generate routes for user activities
rails generate devise User
-
Run the devisecreateusers database migration the was created by in the previous command
rake db:migrate
-
(Re)start the Rails server
kill -USR1 `cat ../tmp/pids/server.pid `; rails server --daemon
-
Place sign up and sign out links on the home page <../app/views/home/index.html.erb>
<h1>Home#index</h1> <%= Time.now %> <li><%= link_to "Sign Up", new_user_registration_path %></li> <li><%= link_to "Sign In", new_user_session_path %></li> <li><%= link_to "Sign Out", destroy_user_session_path, :method => 'delete' %></li> <% if user_signed_in? %> You are signed in, current_user.id = <%= current_user.id %><br /> user_session.keys => <%= user_session.keys %> <% end %>
-
To verify if a user is signed in, use the following helper: usersignedin?
-
See https://github.com/plataformatec/devise#controller-filters-and-helpers
-
<../app/views/home/index.html.erb>
-
For the current signed-in user, this helper is available: currentuser
-
User.new(:email => "user@name.com", :password => 'password', :password_confirmation => 'password').save