我的rails api应用程序突然出现了一个奇怪的问题。
当客户端调用我的一个" get_auth_token"时,我收到以下错误方法。尝试加载基本application_controler类时会触发错误(第1行发生错误)。
对我而言,为什么该应用程序正在运行针对" schema_migrations"的选择,这也是一个谜。在此刻。
Started POST "/register/get_auth_token" for 127.0.0.1 at 2017-12-31 11:56:17 -0800
(1.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
TypeError (wrong argument type Class (expected Module)):
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/registration_controller.rb:1:in `<top (required)>'
Error during failsafe response: wrong argument type Class (expected Module)
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/abstract_controller/helpers.rb:181:in `include'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/abstract_controller/helpers.rb:181:in `block in add_template_helper'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/abstract_controller/helpers.rb:181:in `module_eval'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/abstract_controller/helpers.rb:181:in `add_template_helper'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/abstract_controller/helpers.rb:110:in `block in helper'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/abstract_controller/helpers.rb:109:in `each'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/abstract_controller/helpers.rb:109:in `helper'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.3/lib/action_controller/railties/helpers.rb:17:in `inherited'
/Users/jkramer/RubymineProjects/CrowdWisdomServer/app/controllers/application_controller.rb:1:in `<top (required)>'
/Users/jkramer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:476:in `load'
...
这是应用程序控制器
class ApplicationController < ActionController::Base
include ActionController::MimeResponds
protect_from_forgery with: :null_session
end
实际控制器被调用:
class RegistrationController < ApplicationController
def get_auth_token
token = RegistrationManager.get_instance.get_auth_token(params)
if token.nil?
render json: {status: "authentication_failed"}
return
end
render json: {status: :ok, auth_token: token}
end
end
答案 0 :(得分:0)
当我读到你的问题时,我无法关闭标签,我花了最后一小时刷新等待答案,我试图弄清楚这里有什么问题,这里是我已达到的,我注意到你的ApplicationController
继承自ActionController:Base
,根据此链接中的Adding new Behaviour默认支持ActionController::MimeResponds
,我认为这可能会导致问题,因此您认为从ActionController::API
导入,我没有在一个真实的项目中尝试这个,但我猜,关于你的奇怪为什么rails会针对你的迁移表遇到一个查询,我想你可以找到答案here,这就是我能想到的关于你的问题,希望这有帮助。
答案 1 :(得分:0)
事实证明问题是该行
token=RegistrationManager.get_instance.get_auth_token(params)
指的是我在helpers子目录中有一个名为RegistrationManager的辅助类。由于我仍然不明白的原因,如果你引用一个类而不是生成在helpers目录中的模块,Rails会不高兴。为什么它在第1行失败,我不太确定,但将帮助者的类转移到控制器/关注点解决了问题。我希望错误消息提到错误调用的位置,而不是第1行,可以节省我和Adel先生很多时间!