ActionController::RoutingError (No route matches [PUT] "/") when updating user password

133 views Asked by At
  1. Hey, guys am stack with updating user password with react front end and devise, plus axios which am using to post that on an api.

  2. i have not changed anything from devise but when i hit the api the password is updated and i can use it for login but when i look at the terminal their is an error of ActionController::RoutingError (No route matches [PUT] "/")

  3. any help is highly appreciated

          const onFinish = (values) => {
             setLoading(true);
             const session = { "user": { ...values, reset_password_token: params.get("reset_password_token") } }
             const path = "/users/password"
             setAxiosHeaders();
             axios.put(path, session)
                 .then((response) => {
                     console.log(response.data)
                 })
                 .catch((error) => {
                     console.log(error);
                 })
         }
    
  1. when i hit the api it looks like it is being twice as it throws the same error.
  2. I have tried PATCH method also the same story.
1

There are 1 answers

5
Alex On

Javascript requests (xhr / fetch) redirect with the same http method as original request. You're sending a PUT request and your controller redirects to the root url /, request to the redirected url is issued with a PUT method.

Use status :see_other (aka 303) to redirect with a GET method:

redirect_to root_path, status: :see_other

You can set these options:

Devise.setup do |config|
  config.responder.error_status = :unprocessable_entity
  config.responder.redirect_status = :see_other
end

But it's probably best to set it up for a json response to begin with instead of html.

https://github.com/waiting-for-dev/devise-jwt/wiki/Configuring-devise-for-APIs