Rails 8 edit user password

Rails 8.0.1 Ruby 3.3.6.

I have a new Rails 8 website and I have used the built in authentication generator(rails g authentication).

I need the user to be able to edit their own password when they are already logged in. But I don’t see any page for this?

The only way for a user to edit their password is to use the “Forgot password” link? I was trying to add an <%= link_to "Edit", edit_password_path(params[:token]) %> link to my template.

I see there is already a PasswordsController with edit and update actions. But they are only if using password reset link?

So do I have to create a separate/ different controller. A UsersController with edit & update actions? And I need to pass a session token? I just copy/ recreate the Password controller but call it UsersController? Am I not just repeating everything in PasswordsController?

I see online there are lots of examples of adding user registration, but nothing about letting a user edit their own password.

It’s mostly included in the Rails 8 Authentication. You’re on the right track. Just need to pass the Current.user to edit_password_url …

  <%= link_to "Change Password", edit_password_url(Current.user.password_reset_token) %>

Here’s a super basic app that has password reset function:

Cheers

1 Like

Hi Shannon,

Thanks a million, that did the job!!

I was just trying to pass the token part. I was missing the Current.user bit. I was thinking I’d have to create a User controller.

Thanks again, that’s a huge help.

1 Like