在加载/login/时,我在我的日志文件中得到以下内容。
Started GET "/login" for 120.138.93.108 at 2016-01-02 03:06:24 +0000
ActionController::RoutingError (Couldn't find SessionsHelper, expected it to be defined in helpers/sessions_helper.rb): app/controllers/application_controller.rb:1:in
‘app/controllers/sessions_controller.rb:1:in
’
但是,sessions_helper.rb确实存在于helpers文件夹中。此外,application_controller.rb和sessions_controller.rb被定义为类,session_helper.rb被定义为模块。
会出什么问题呢?
发布于 2017-10-01 02:13:58
我也遇到过类似的问题:
Couldn't find AgileTeamsHelper, expected it to be defined in helpers/agile_teams_helper.rb
事实证明,我在我的助手中定义了这个:
module AgileTeamHelper
def td_color(text)
if text == "Green"
"green-background"
elsif text == "Yellow"
"yellow-background"
elsif text == "Red"
"red-background"
end
end
end
而不是:
module AgileTeamsHelper # <-- (Notice the extra s after teams)
def td_color(text)
if text == "Green"
"green-background"
elsif text == "Yellow"
"yellow-background"
elsif text == "Red"
"red-background"
end
end
end
在这种情况下,我遗漏了“AgileTeamsHelper”中的“%s”。我相信rails寻找一个与helper相同的模块,但是camel是大小写的。即。'agile_teams_helper'.camelize
-> "AgileTeamsHelper"
发布于 2019-06-10 09:45:23
TL;DR
有时这不是帮助者的问题。删除所有帮助器,看看接下来会发生什么。
正文
似乎如果控制器本身的加载(读取类文件,计算内容以定义内部定义的类/模块)由于某种原因而失败,则会显示此错误。
在我的例子中,有一个来自gem的类,它打算由include
ing用于控制器,它覆盖了included
方法,并执行了一些初始化过程。问题是,这个include
方法引发了一个异常,它阻止了控制器的加载,我不知道为什么,但结果就像这个问题中描述的那样。
我通过删除所有助手并检查接下来会发生什么,找出了根本原因。如果错误发生变化,并且您发现它发生在加载控制器时,那么现在您可以修复它。
# Example class of what have caused the Helper not found in my case
class FooController
include SomeGemWhichRaiseExceptionOnInclude
end
发布于 2016-01-02 11:38:43
我通过重新创建helpers/sessionhelper.rb(使用touch)并用完全相同的内容填充它,解决了这个问题。很奇怪,但很管用。
https://stackoverflow.com/questions/34562224
复制相似问题