1
votes

I do authorization through "login" and because of this there is such an error:

Started POST "/auth/sign_in" for 10.12.4.5 at 2018-08-07 10:20:55 +0500

LoadError (Unable to autoload constant Overrides::SessionsController, expected /home/admin/Рабочий стол/demo/backend/app/controllers/overrides/sessions_controller.rb to define it):

activesupport (5.1.6) lib/active_support/dependencies.rb:512:in load_missing_constant' activesupport (5.1.6) lib/active_support/dependencies.rb:202:inconst_missing' activesupport (5.1.6) lib/active_support/inflector/methods.rb:284:in const_get' activesupport (5.1.6) lib/active_support/inflector/methods.rb:284:inblock in constantize' activesupport (5.1.6) lib/active_support/inflector/methods.rb:267:in each' activesupport (5.1.6) lib/active_support/inflector/methods.rb:267:ininject' activesupport (5.1.6) lib/active_support/inflector/methods.rb:267:in constantize' activesupport (5.1.6) lib/active_support/dependencies.rb:583:inget' activesupport (5.1.6) lib/active_support/dependencies.rb:614:in constantize' actionpack (5.1.6) lib/action_dispatch/http/request.rb:85:incontroller_class_for' actionpack (5.1.6) lib/action_dispatch/http/parameters.rb:99:in binary_params_for?' actionpack (5.1.6) lib/action_dispatch/http/parameters.rb:90:inset_binary_encoding' actionpack (5.1.6) lib/action_dispatch/http/parameters.rb:67:in path_parameters=' actionpack (5.1.6) lib/action_dispatch/journey/router.rb:48:inblock in serve' actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in each' actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:inserve' actionpack (5.1.6) lib/action_dispatch/routing/route_set.rb:844:in call' warden (1.2.7) lib/warden/manager.rb:36:inblock in call' warden (1.2.7) lib/warden/manager.rb:35:in catch' warden (1.2.7) lib/warden/manager.rb:35:incall' rack (2.0.5) lib/rack/etag.rb:25:in call' rack (2.0.5) lib/rack/conditional_get.rb:38:incall' rack (2.0.5) lib/rack/head.rb:12:in call' activerecord (5.1.6) lib/active_record/migration.rb:556:incall' actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:26:in block in call' activesupport (5.1.6) lib/active_support/callbacks.rb:97:in run_callbacks' actionpack (5.1.6) lib/action_dispatch/middleware/callbacks.rb:24:in call' actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:incall' actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:59:in call' actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:incall' railties (5.1.6) lib/rails/rack/logger.rb:36:in call_app' railties (5.1.6) lib/rails/rack/logger.rb:24:inblock in call' activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in block in tagged' activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in tagged' railties (5.1.6) lib/rails/rack/logger.rb:24:incall' actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in call' request_store (1.4.1) lib/request_store/middleware.rb:19:incall' actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in call' rack (2.0.5) lib/rack/runtime.rb:22:incall' activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in call' actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:incall' actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in call' rack (2.0.5) lib/rack/sendfile.rb:111:incall' rack-cors (1.0.2) lib/rack/cors.rb:97:in call' railties (5.1.6) lib/rails/engine.rb:522:incall' puma (3.11.4) lib/puma/configuration.rb:225:in call' puma (3.11.4) lib/puma/server.rb:632:inhandle_request' puma (3.11.4) lib/puma/server.rb:446:in process_client' puma (3.11.4) lib/puma/server.rb:306:inblock in run' puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

TypeError (superclass mismatch for class SessionsController):

app/controllers/overrides/sessions_controller.rb:1:in `'

/overrides/sessions_controller.rb:

class SessionsController < DeviseTokenAuth::ApplicationController

  def resource_data(opts = {})
    opts[:resource_json] || @resource.as_json
  end

  def render_new_error
    render json: {
      errors: [I18n.t("devise_token_auth.sessions.not_supported")]
    }, status: 405
  end

  def render_create_success
    render json: {
      sponsor: resource_data(resource_json: @resource.userable.token_validation_response)
    }
  end

  def render_create_error_not_confirmed
    render json: {
      errors: [I18n.t("devise_token_auth.sessions.not_confirmed", login: @resource.login)]
    }, status: 404
  end

  def render_create_error_bad_credentials
    render json: {
      errors: [I18n.t("devise_token_auth.sessions.bad_credentials")]
    }, status: 402
  end

  def render_destroy_success
    render json: {
    }, status: 200
  end

  def render_destroy_error
    render json: {
      errors: [I18n.t("devise_token_auth.sessions.user_not_found")]
    }, status: 404
  end

end

application_controller.rb:

class ApplicationController < ActionController::API
  include DeviseTokenAuth::Concerns::SetUserByToken
end

routes.rb:

Rails.application.routes.draw do
  mount_devise_token_auth_for 'User', at: 'auth', controllers: {
    sessions:  'overrides/sessions'
  }
end
1
Have you tried class Overrides::SessionsController? It looks like it should be namespaced.jvillian

1 Answers

2
votes

Actually the error message says what needs to be done:

Unable to autoload constant Overrides::SessionsController, expected /home/admin/Рабочий стол/demo/backend/app/controllers/overrides/sessions_controller.rb to define it)

Rails expects app/controllers/overrides/sessions_controller.rb to define Overrides::SessionsController, but can't find it.

Change your controller class definition to:

class Overrides::SessionsController < DeviseTokenAuth::ApplicationController
  ...
end