我通过“登录”进行授权,因此会出现这样的错误:
在2018-08-07 10:20:55为10.12.4.5开始POST“ / auth / sign_in” +0500
LoadError(无法自动加载常量Overrides :: SessionsController, 预期的/ home / admin /Рабочий стол/ demo / backend / app / controllers / overrides / sessions_controller.rb至 定义它):
activesupport(5.1.6)lib / active_support / dependencies.rb:512:in
load_missing_constant' activesupport (5.1.6) lib/active_support/dependencies.rb:202:in
const_missing' activesupport(5.1.6)lib / active_support / inflector / methods.rb:284:inconst_get' activesupport (5.1.6) lib/active_support/inflector/methods.rb:284:in
阻止常量化” activesupport(5.1.6)lib / active_support / inflector / methods.rb:267:ineach' activesupport (5.1.6) lib/active_support/inflector/methods.rb:267:in
注入'主动支持 (5.1.6)lib / active_support / inflector / methods.rb:267:inconstantize' activesupport (5.1.6) lib/active_support/dependencies.rb:583:in
get' activesupport(5.1.6)lib / active_support / dependencies.rb:614:inconstantize' actionpack (5.1.6) lib/action_dispatch/http/request.rb:85:in
controller_class_for' actionpack(5.1.6)lib / action_dispatch / http / parameters.rb:99:inbinary_params_for?' actionpack (5.1.6) lib/action_dispatch/http/parameters.rb:90:in
set_binary_encoding' actionpack(5.1.6)lib / action_dispatch / http / parameters.rb:67:inpath_parameters=' actionpack (5.1.6) lib/action_dispatch/journey/router.rb:48:in
阻止发球 actionpack(5.1.6)lib / action_dispatch / journey / router.rb:33:ineach' actionpack (5.1.6) lib/action_dispatch/journey/router.rb:33:in
serve' actionpack(5.1.6)lib / action_dispatch / routing / route_set.rb:844:incall' warden (1.2.7) lib/warden/manager.rb:36:in
阻止通话” 管理员(1.2.7)lib / warden / manager.rb:35:incatch' warden (1.2.7) lib/warden/manager.rb:35:in
呼叫机架(2.0.5)lib / rack / etag.rb:25:incall' rack (2.0.5) lib/rack/conditional_get.rb:38:in
呼叫机架 (2.0.5)lib / rack / head.rb:12:在call' activerecord (5.1.6) lib/active_record/migration.rb:556:in
中调用'Actionpack(5.1.6) lib / action_dispatch / middleware / callbacks.rb:26:在block in call' activesupport (5.1.6) lib/active_support/callbacks.rb:97:in
run_callbacks的操作包(5.1.6)中 lib / action_dispatch / middleware / callbacks.rb:24:incall' actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in
call' 动作包(5.1.6) lib / action_dispatch / middleware / debug_exceptions.rb:59:在call' actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in
通话中 railties(5.1.6)lib / rails / rack / logger.rb:36:在call_app' railties (5.1.6) lib/rails/rack/logger.rb:24:in
中阻止通话中的activesupport (5.1.6)lib / active_support / tagged_logging.rb:69:在block in tagged' activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in
标签为'activesupport(5.1.6)中 lib / active_support / tagged_logging.rb:69:tagged' railties (5.1.6) lib/rails/rack/logger.rb:24:in
通话中的actionpack(5.1.6) lib / action_dispatch / middleware / remote_ip.rb:79:在call' request_store (1.4.1) lib/request_store/middleware.rb:19:in
通话中 (5.1.6)lib / action_dispatch / middleware / request_id.rb:25:incall' rack (2.0.5) lib/rack/runtime.rb:22:in
致电“ activesupport(5.1.6)” lib / active_support / cache / strategy / local_cache_middleware.rb:27:incall' actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in
通话'行动包 (5.1.6)lib / action_dispatch / middleware / static.rb:125:在call' rack (2.0.5) lib/rack/sendfile.rb:111:in
中调用'rack-cors(1.0.2) lib / rack / cors.rb:97:在call' railties (5.1.6) lib/rails/engine.rb:522:in
中叫'美洲狮(3.11.4) lib / puma / configuration.rb:225:incall' puma (3.11.4) lib/puma/server.rb:632:in
handle_request'puma(3.11.4) lib / puma / server.rb:446:inprocess_client' puma (3.11.4) lib/puma/server.rb:306:in
中的run'puma块(3.11.4) lib / puma / thread_pool.rb:120:in`spawn_thread中的块'TypeError(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
结束
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
答案 0 :(得分:2)
实际上,错误消息指出需要做什么:
无法自动加载常量Overrides :: SessionsController,需要/ home / admin /Рабочийстол/ demo / backend / app / controllers / overrides / sessions_controller.rb进行定义)
Rails
期望app/controllers/overrides/sessions_controller.rb
定义Overrides::SessionsController
,但找不到它。
将您的控制器类定义更改为:
class Overrides::SessionsController < DeviseTokenAuth::ApplicationController
...
end