Ask A Question


You’re not receiving notifications from this thread.

How do I separate out the devise form like (edit profile, edit password)?

Lance Williams asked in General

I've followed this link, but would like to just use the update action and not have to use update_password & update_profile custom actions.

Chris, on on the settings page you have 'edit profile' and 'edit password' going to the default 'update action'. What kind of logic did you use to allow multiple forms submitting to the /users (update) action.

Thanks so much!


update: I did it the hard way. Chris already has a video on this:

I think I figured it out. I don't know if it's the best way but it seems to be working. I'm brand new to rails so I'm learning as I go. Thanks for the awesome content Chris.

In the UsersController in the update action I added:

if params[:commit] == "Update Profile"
  # logic for update profile form
if params[:commit] == "Update Password"
  # logic for update password form

In the edit.html.erb file the form submit button value name matched the params[:commit] comparison like this:

<%= form_for(@user, url: {action: "update"}, html: {id: "profile"}) do |f| %>
  # profile fields go here
  <%= f.submit "Update Profile" %>
<% end %>
<%= form_for(@user, url: {action: "update"}, html: {id: "password"}) do |f| %>
  # password fields go here
  <%= f.submit "Update Password" %>
<% end %>

in routes.rb I put this:

resource :user, only: [:edit, :update]

Yup, that's basically how I did it too. :)

I just created two form_fors and separated them out. Since both of mine run through Devise, you don't have to do any of the updates to the action because it will just save whatever fields you pass in and it doesn't matter which button was submitted because the logic doesn't change.

You might be able to refactor your action so that it handles things the same way. Basically always try to update the name and profile information. If you didn't receive and field data for it, then no updates are applied. Same for the password. If you didn't pass in the field, it won't attempt to update the password. That would help you remove those two if statements. :)

Hi Chris, is there a way we could separate this into two pages, with a page to update password and a page to update profile ? i am also new to Rails and have been trying for the last 2 days. It seems easy but for some reason I am getting a lot of errors
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 84,387+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.