0

I am trying to send a POST request (using Postman) to sign up a new user using devise token auth and I am overriding the registrations controller to enable my own JSON responses.

I keep getting a routing error:

"status": 404,
    "error": "Not Found",
    "exception": "#<ActionController::RoutingError: uninitialized constant Overrides>"

Here is my registrations controller:

module Api
  module V1
   module Overrides
     class RegistrationsController < DeviseTokenAuth::RegistrationsController

   respond_to :json
    def create

      user = User.new(params[:user])
      if user.save
        render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
        return
      else
        warden.custom_failure!
        render :json=> user.errors, :status=>422
       end
     end
    end
  end
 end
end

Here is my routes file:

Rails.application.routes.draw do


  namespace :api do
   scope :v1 do
    mount_devise_token_auth_for 'User', at: 'auth', controllers: {

    registrations: 'overrides/registrations',
    sessions: 'overrides/sessions'

}
    end
  end
end

Where have I gone wrong in my routes?

  • I don't think `mount_devise_token_auth_for` takes the route nesting into account so you need to provide the module nesting: `registrations: 'api/v1/overrides/registrations'`. But that controller is has got some other serious issues like `User.new(params[:user])` which will cause a unpermitted parameters error and you really need to do some research on how to override the devise controllers properly. – max May 18 '20 at 21:15
  • Like if you look at the code for [the superclass](https://github.com/lynndylanhurley/devise_token_auth/blob/master/app/controllers/devise_token_auth/registrations_controller.rb) you can see that you can just override the `render_create_success` and `render_create_error` methods to customize the response instead of clobbering the whole thing. – max May 18 '20 at 21:40
  • @max - it all makes sense now haha . Thank you – Ryan McClure May 18 '20 at 22:09

0 Answers0