Book Image

Learning Devise for Rails

By : Giovanni Sakti, Hafiz Badrie Lubis, Nia Mutiara
Book Image

Learning Devise for Rails

By: Giovanni Sakti, Hafiz Badrie Lubis, Nia Mutiara

Overview of this book

<p>There are numerous ways of implementing user sign-ins on your Rails web applications. Of those different ways, using Devise is one of the most popular, quick and flexible way to get user sign-ins working. It is extensible and plays well with other gems such as CanCan (for user privileges) and OmniAuth (for Facebook and Twitter sign-ins).</p> <p>A hands-on, all-in-one guide that gives you step-by-step instructions along with code examples to implement authentication systems in your application. This book will help you to implement various schemes of authentication systems including authorization and remote authentication, using Devise.</p> <p>Helping you make your Rails applications more accessible and user-friendly; this book explains how to implement user sign-ins in Rails. It will also show you how to customize user authentication pages, such as sign-in, sign-up, forgot password, and account details, by making use of existing Devise views. In addition, you will learn about facilitating complex privilege rules using the CanCan gem. Finally, you will discover how to make sure your authentication codes work as expected by using integration tests.</p> <p>You will learn all you need to know to create user email and social network sign-ins quickly, to customize user sign-in-related views, and implement complex privileges, as well as to ensure the stability of your authentication codes by testing them.</p>
Table of Contents (12 chapters)

Customizing your Devise layout


There are times when you have more than one Devise model in one application, and a question comes to your mind, such as "How do I maintain its views so that they will have different views?" Previously, I wrote about generating views, so you can make some custom changes to the views by executing the following command:

$ rails generate devise:views

Now, you are going to learn about how to generate scoped views in Devise. At first, you need to make a little modification to config/initializers/devise.rb. You need to remove the comment tag for this code:

config.scoped_views = true

This code will enable scoped views for Devise, so you can generate some specific views for your Devise model.

Before we start generating views, let's have two new Devise models for admin and employee as the examples. Now, you can generate scoped views for your Devise model by executing this command:

$ rails generate devise:views admins
$ rails generate devise:views employees

The following...