Devise for Authentication on Rails 4
Automatically Installing User Login with Prelang
Sign up for Prelang to use this feature.
Installation
Prelang automates the entire process of installing Devise, an excellent user authentication gem for Ruby on Rails 4, which handles user login for your application. This guide will go over what the User Login feature adds and explain all of the options which Prelang supports.
Adding this feature will automatically perform these steps on your application:
- Installs Devise (gem, initializer, etc.)
- Generates a User model (See below)
- Defines a
require_user_signed_in
filter inApplicationController
for use in other controllers. If set, this requires the user to be signed in to view certain controllers or actions.
After adding the feature, you will be presented with a list of options.
Facebook Login Support
Allowing users to login to your application with Facebook can easily be achieved by toggling this option. This adds the omniauth
and omniauth-facebook
gems and injects a few methods into your User model to store and find users by their Facebook IDs. It also creates a migration for adding uid
to User.
Note: See Post Generation Steps
Editable Views
This option will generate views at app/views/devise
which you can use to customize the default Devise views for Login, Sign Up, and Account which allows you to add your own styling and layout.
Editable Controllers
Similarly, the Editable Controllers will generate controllers at app/controllers/users
which allow you to customize the behavior of Devise controllers. Each of them calls a super
method to hook into the original Devise controllers.
Username Login Support
This option will add a username string attribute to the User model (with a migration) and allow users to login with either a username or email address. It updates the Devise views for Sign Up (to add a username field) and Login (to add a universal field for either email or username) and plays nicely with the UI Framework / Twitter Bootstrap feature.
Stylized Paths
The default Devise paths look something like this: /users/sign_up
. Many users want to change these paths to prettier ones like /signup
and /login
so toggling this option will do just that. All of the changes will live inroutes.rb
.
After Generation
If you've toggled the Facebook Login option, you'll need to set your FACEBOOK_SECRET_ID
ENV variable. Adding the ENV Variables feature makes this easy... You'll only need to set that in your .env
file on development.
Automatic Rails Development Tools