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)

Updating the user account


Basically, you are already allowed to access your user account when you activate the registerable module in the model. To access the page, you need to log in first and then go to /users/edit. The page is as shown in the following screenshot:

The edit account page

But, what if you want to edit your username or e-mail ID? How will you do that? What if you have extra information in your users table, such as addresses, birth dates, bios, and passwords as well? How will you edit these? Let me show you how to edit your user data including your password, or edit your user data without editing your password.

  • Editing your data, including the password: To perform this action, the first thing that you need to do is modify your view. Your view should contain the following code:

    <div><%= f.label :username %><br />
    <%= f.text_field :username %></div>

    Now, we are going to overwrite Devise's logic. To do this, you have to create a new controller named...