我在加载/ 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定义为Classes,session_helper.rb定义为模块。
可能出现什么问题?
答案 0 :(得分:2)
我遇到了类似的问题:
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
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会寻找一个与帮助器相同的模块,但是驼峰很有用。 IE浏览器。 'agile_teams_helper'.camelize
- > "AgileTeamsHelper"
答案 1 :(得分:1)
我通过重新创建helpers / sessions_helper.rb(使用触摸)并使用完全相同的内容填充它来解决了这个问题。很奇怪,但它确实有效。
答案 2 :(得分:1)
我只是遵循古老的建议:
如有疑问,请重启服务器
这对我来说已经足够了。我完全确定代码没问题。
答案 3 :(得分:1)
有时候这不是助手的问题。删除所有帮助者,然后看看接下来会发生什么。
似乎由于某种原因,控制器本身的加载(读取类文件,评估内部定义的类/模块的内容)失败,就会显示此错误。
在我的案例中,有一个来自gem的类,打算供include
使用到控制器,该类重写included
方法,并进行了一些初始化过程。问题是,此include
方法引发了一个异常,阻止了Controller的加载,我不知道为什么,但导致的情况与此问题中所述的一样。
我找到了根本原因,方法是删除所有帮助程序并检查接下来会发生什么。如果错误发生变化,而您发现它是在加载Controller时发生的,那么现在就可以修复它。
# Example class of what have caused the Helper not found in my case
class FooController
include SomeGemWhichRaiseExceptionOnInclude
end
答案 4 :(得分:0)
正如其他人指出的那样,这可能不是助手的问题,助手的错误可能掩盖了真正的问题。至少这是我将 Rails 4 应用程序升级到 Rails 5 的经验。
@TKChattoraj 建议 here,与其删除 Rails 5+ 中的所有助手,不如将 config.action_controller.include_all_helpers = false
添加到 config/environments/development.rb,这将消除来自助手的任何误报.至少这对我有用。
答案 5 :(得分:-1)
就我而言,我有一个:
包含ModuleName
指向模型中的非现有模块。 这个之前已被删除,但我错过了参考。
我的应用程序中的每个助手都有完全相同的“Coul not find ...”错误,所以很难找出问题的来源。