0
votes

I am using Devise to authenticate users. I am trying to make a form/update method to update the password. The form generates correctly and it picks up the route as well. However, I am receiving the following error:

"Could not find devise mapping for path "/users/updatepw". This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user]"

The first option doesn't seem to be the cause, this is my routes.rb:

devise_scope :users do
  ...
  post "/users/updatepw", to: "users/registrations#update_password", as :update_pw
  ...  
end
...
resources :users #I don't know if this is needed considering the devise block, but commenting it out doesn't fix the problem..

So it is wrapped.

As for the second option...I don't really understand it...I am not trying to test anything...?

My question is really 2-fold: 1) What does the error mean, considering I'm not trying to run any tests? 2) Where do I put the corrective line ("@request.env["devise.mapping"] = Devise.mappings[:user]") to fix the problem?

1

1 Answers

0
votes

I think you are missing the as: resource_name option in your form. See Devise's password edit

<%= form_for(resource, as: resource_name, ...

https://github.com/plataformatec/devise/blob/master/app/views/devise/passwords/edit.html.erb#L3

Question: Why are you creating your own update password? Devise already provides this.