首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >获取:“找不到会话,希望它在helpers/ SessionsHelper _helper.rb中定义”

获取:“找不到会话,希望它在helpers/ SessionsHelper _helper.rb中定义”
EN

Stack Overflow用户
提问于 2016-01-02 11:11:47
回答 4查看 6.2K关注 0票数 4

在加载/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:inapp/controllers/sessions_controller.rb:1:in

但是,sessions_helper.rb确实存在于helpers文件夹中。此外,application_controller.rb和sessions_controller.rb被定义为类,session_helper.rb被定义为模块。

会出什么问题呢?

EN

回答 4

Stack Overflow用户

发布于 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"

票数 3
EN

Stack Overflow用户

发布于 2019-06-10 09:45:23

TL;DR

有时这不是帮助者的问题。删除所有帮助器,看看接下来会发生什么。

正文

似乎如果控制器本身的加载(读取类文件,计算内容以定义内部定义的类/模块)由于某种原因而失败,则会显示此错误。

在我的例子中,有一个来自gem的类,它打算由includeing用于控制器,它覆盖了included方法,并执行了一些初始化过程。问题是,这个include方法引发了一个异常,它阻止了控制器的加载,我不知道为什么,但结果就像这个问题中描述的那样。

我通过删除所有助手并检查接下来会发生什么,找出了根本原因。如果错误发生变化,并且您发现它发生在加载控制器时,那么现在您可以修复它。

# Example class of what have caused the Helper not found in my case
class FooController
  include SomeGemWhichRaiseExceptionOnInclude
end
票数 2
EN

Stack Overflow用户

发布于 2016-01-02 11:38:43

我通过重新创建helpers/sessionhelper.rb(使用touch)并用完全相同的内容填充它,解决了这个问题。很奇怪,但很管用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34562224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档