-
Notifications
You must be signed in to change notification settings - Fork 0
Step07: Adding Devise
Note: These are the mose frequently used helper methods (assuming a User model) available to you after install: user_signed_in?
, current-user
, and user_session
-
Make sure you have
gem 'devise'
in your Gemfile. -
$ rails g devise:install
-
Add
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
toconfig/environment/development.rb
-
Add root to: 'static_pages#home' if you haven't yet (or whatever your root is).
-
Flash messages should already be enabled if you followed the Bootstrap setup, otherwise add
%= notice
and%= alert
to a shared partial (If you're confused about this see #9 of Step06). -
Add the following line to
config/application.rb
:# FOR DEVISE ON HEROKU!!! config.assets.initialize_on_precompile = false
-
Run
$ rails g devise user
to create the User model -
Set
config.scoped_views = true
insideconfig/initializers/devise.rb
to allow for multiple models in the future. -
Inside your migration file -
db/migrate/..._devise_create_users.rb
- uncomment out the lines below## Confirmable
,## Lockable
, and## Token authenticatable
if you wish to provide email confirmation and verification, lockouts after a certain number of failed attempts, and the ability to authenticate using a single access token (read more about single access tokens). Also uncomment the corresponding indexes. -
Run
$ rake db:migrate
-
Optionally add name and username to User model with
$ rails g migration add_names_to_users name:string username:string
, then$ rake db:migrate
. If you plan on having a lot of users, also add indices to these columns withrails generate migration add_indices_to_users
and then in the generated migration file:class AddIndicesToUsers < ActiveRecord::Migration def change end add_index :users, :name add_index :users, :username, :unique => true end
-
Add a comma followed by
:lockable, :confirmable, :token_authenticatable
to thedevise
call inapp/models/user.rb
. -
Add Lockable: In
config/initializers/devise.rb
, uncomment the lines# config.lock_strategy = :failed_attempts
,# config.unlock_keys = [:email]
,# config.unlock_strategy = :both
and# config.maximum_attempts = 20
(we set it to 8). -
Add Confirmable: In addition to what we've already done, uncomment
config.allow_unconfirmed_access_for = 2.days
inconfig/initializers/devise.rb
to allow users to access the website without confirming for a specified amount of time (change to whatever you like). Setconfig.mailer_sender
to the email address you want to be shown in your Devise::Mailer, i.e.config.mailer_sender = "info@rangular.io"
Additional setup is still necessary. If you wish to perform this now, please go to Step08 of the Wiki. -
Add Token Authenticatable: In
config/initializers/devise.rb
uncomment out# config.token_authentication_key = :auth_token
if you plan to implement the versioned RESTful API for communicating with our Angular App.
- Run
$ rails g devise:views users
to generate our first scoped view.