Allow Users to Edit their Account in a Rails App with Devise
In this lesson we are going to see how to build the feature that allows users to edit their account details and also walk through how to customize the Devise notification messages.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this lesson we are going to see how to build the feature that allows users to edit their account details and also walk through how to customize the Devise notification messages.

To start with, I'm going to find out the path that allows users to edit their information and for this, I'm going to type the command,

rake routes | grep user

This will display all the routes with the word user in it.

large

From this list, I can see that the path is edit_user_registration.

Next, go to the file _nav.html.erb and add a link for edit.

<%= link_to "Edit Account", edit_user_registration_path %>

This method takes no parameters.

large

If you hit the refresh button on your browser, you can see the Edit Account link, and when you click on it, you go to a screen that allows you to change your email id and password. Before clicking the "Update" button, make sure you enter your current password, otherwise you will get an error. This idea of entering your current password adds another layer of security to your application.

medium

If you'd like, click the Edit Account link again, and you can see the updated email ID.

Another cool thing you can do is allow your users to cancel their account. To try if it works, I click on the button Cancel my account and a pop-up window asks me to confirm it.

large

Once I click Ok, it takes me to the home page with a message that confirms my cancellation.

medium

Now, if you want to customize these messages, an easy way is to copy it and search it in your sublime editor. When you do that, you can see that all these messages are contained in /config/locales/devise.en.yml file. If you open this file, you can see all the messages here.

large

You can customize all of these messages. You can make changes and test them out on your browser, but make sure to restart your server because this change is happening in the config directory.