【问题标题】:Rails: AbstractController::Helpers::MissingHelperError - Missing helper file application_helper.rb_helper.rbRails:AbstractController::Helpers::MissingHelperError - 缺少帮助文件 application_helper.rb_helper.rb
【发布时间】:2015-03-09 05:03:59
【问题描述】:

找不到任何对我有帮助的资源!当我尝试“rails s”并转到应用程序的任何页面时;它告诉我这个错误页面说我缺少帮助文件。

我认为它在我的台式机上是本地的,因为我最近对笔记本电脑上的应用程序做了一些工作。我从笔记本电脑推送,应用程序在 Heroku 上运行良好,并在该机器上本地运行,零问题。我添加了一项使用 Carrierwave、Mini_Magick 和 Fog 将公司徽标图像上传到 Amazon S3 的功能。

到目前为止我已经尝试过的事情:我已经删除了应用程序并将其 git clone 回这台机器。我已经尝试过 Brew 卸载/安装 imagemagick 并在克隆应用程序后完成了所有基础知识,例如捆绑安装、rake db:migrate。还是没有运气..

这是我在页面上得到的错误代码以及完整的跟踪:

AbstractController::Helpers::MissingHelperError in PagesController#dashboard
Missing helper file helpers//users/jamesfend/sites/feedbackz/app/helpers/application_helper.rb_helper.rb

Extracted source (around line #1):
1 class ApplicationController < ActionController::Base    
2 # Prevent CSRF attacks by raising an exception.
3 # For APIs, you may want to use :null_session instead.
4 protect_from_forgery with: :exception

完整跟踪

actionpack (4.2.0) lib/abstract_controller/helpers.rb:151:in `rescue in block in modules_for_helpers'
actionpack (4.2.0) lib/abstract_controller/helpers.rb:148:in `block in modules_for_helpers'
actionpack (4.2.0) lib/abstract_controller/helpers.rb:144:in `map!'
actionpack (4.2.0) lib/abstract_controller/helpers.rb:144:in `modules_for_helpers'
actionpack (4.2.0) lib/action_controller/metal/helpers.rb:93:in `modules_for_helpers'
actionpack (4.2.0) lib/abstract_controller/helpers.rb:108:in `helper'
actionpack (4.2.0) lib/action_controller/railties/helpers.rb:17:in `inherited'
app/controllers/application_controller.rb:1:in `<top (required)>'
activesupport (4.2.0) lib/active_support/dependencies.rb:457:in `load'
activesupport (4.2.0) lib/active_support/dependencies.rb:457:in `block in load_file'
activesupport (4.2.0) lib/active_support/dependencies.rb:647:in `new_constants_in'
activesupport (4.2.0) lib/active_support/dependencies.rb:456:in `load_file'
activesupport (4.2.0) lib/active_support/dependencies.rb:354:in `require_or_load'
activesupport (4.2.0) lib/active_support/dependencies.rb:494:in `load_missing_constant'
activesupport (4.2.0) lib/active_support/dependencies.rb:184:in `const_missing'
app/controllers/pages_controller.rb:1:in `<top (required)>'
activesupport (4.2.0) lib/active_support/dependencies.rb:457:in `load'
activesupport (4.2.0) lib/active_support/dependencies.rb:457:in `block in load_file'
activesupport (4.2.0) lib/active_support/dependencies.rb:647:in `new_constants_in'
activesupport (4.2.0) lib/active_support/dependencies.rb:456:in `load_file'
activesupport (4.2.0) lib/active_support/dependencies.rb:354:in `require_or_load'
activesupport (4.2.0) lib/active_support/dependencies.rb:494:in `load_missing_constant'
activesupport (4.2.0) lib/active_support/dependencies.rb:184:in `const_missing'
activesupport (4.2.0) lib/active_support/inflector/methods.rb:261:in `const_get'
activesupport (4.2.0) lib/active_support/inflector/methods.rb:261:in `block in constantize'
activesupport (4.2.0) lib/active_support/inflector/methods.rb:259:in `each'
activesupport (4.2.0) lib/active_support/inflector/methods.rb:259:in `inject'
activesupport (4.2.0) lib/active_support/inflector/methods.rb:259:in `constantize'
activesupport (4.2.0) lib/active_support/dependencies.rb:566:in `get'
activesupport (4.2.0) lib/active_support/dependencies.rb:597:in `constantize'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:69:in `controller_reference'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:59:in `controller'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:38:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/Users/jamesfend/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/jamesfend/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/jamesfend/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

页面控制器

class PagesController < ApplicationController

  def dashboard
    @title = 'Feedbackz by Amazio Labs'
    @header_title = 'Dashboard'
  end

  def billing
    @title = 'Billing & Plans - Feedbackz by Amazio Labs'
    @header_title = 'Billing & Plans'    
    @user = User.find(current_user.id)
  end

  def contact
    @title = 'Contact - Feedbackz by Amazio Labs'
    @header_title = 'Contact Us'    
  end

  def faq
    @title = 'FAQ - Feedbackz by Amazio Labs'
    @header_title = 'Frequently Asked Questions'    
  end

  def invoices
    @title = 'Invoices - Feedbackz by Amazio Labs'
    @header_title = 'Invoices'    
  end  

  def videos
    @title = 'Videos - Feedbackz by Amazio Labs'
    @header_title = 'Helpful Videos'    
  end

  def schedule
    @title = 'Schedule - Feedbackz by Amazio Labs'
    @header_title = 'Schedule of Pending Sends'    
  end

end

【问题讨论】:

  • 您的 PagesController 或应用程序中的其他任何地方是否有类似 helper :application_helper.rb 的内容?如果是这样,它应该被缩短为helper :application
  • 嘿,感谢您的快速回复。我在文件夹范围内搜索“application_helper”,不幸的是,代码中的任何地方都没有匹配项。
  • 你还能从 PagesController 中附加代码吗?
  • @swistaku - 已粘贴..
  • 对我来说这似乎是 ruby​​/rails 错误,请查看此处stackoverflow.com/questions/27871726/… 和此处d.hatena.ne.jp/jiikko/20150108

标签: ruby-on-rails ruby-on-rails-4


【解决方案1】:

这对我有用:

cd ~
mv sites tmpsites
mv tmpsites sites

我也这样做了,但不确定是否需要:

cd /
sudo ln -s Users users

奇怪的是,我看不到小写的 users 符号链接,但 ls /usersls /Users 都可以工作。

【讨论】:

  • 我做了第一部分,它就像一个魅力。我不必做第二部分。谢啦!你是一个救生员..
  • 您能解释一下这是如何解决问题的,或者这个解决方案与问题的关系吗?
  • 我不记得它是如何或为什么起作用的;只是它以某种方式解决了这个问题,即使它似乎没有意义! ?
【解决方案2】:

我用控制台中的“spring stop”解决了。

【讨论】:

  • 我在运行测试套件时收到 AbstractController::Helpers::MissingHelperError: 显示自定义控制器助手丢失。按照终端(Linux)的建议运行“spring stop”并重新运行测试套件立即成功,无需其他操作。
  • 您能否更详细地解释为什么会发生这种情况?
【解决方案3】:

分步指南:

在 OSX 上,我已将用户名从 psy 更改为 Psy。所以解决这个问题是一件很痛苦的事情。遵循这些步骤帮助了我:

  1. 运行irb 并在您的项目文件夹中执行此命令:

    File.expand_path("./")
    # => "/Users/psy/code/rails_app"
    
  2. 现在退出 irb 并在你的 shell 中运行这个命令:

    $ pwd
    # => /Users/Psy/code/rails_app
    
  3. 比较两者,注意大小写不同的目录,本例为Psy

  4. 将该目录重命名为任何内容,然后将其重命名回原始文件夹(如有必要,请使用sudo

    $ sudo mv /Users/Psy /Users/tmp
    $ sudo mv /Users/tmp /Users/Psy
    

【讨论】:

    【解决方案4】:

    虽然 Zubin 提供的答案在我的个人机器上对我有用,但我只是在工作机器上遇到了同样的问题,但它并不完全正确。我将网站创建为小写目录:

    mkdir sites 
    

    用大写s重命名修复了它。

    mv sites Sites
    

    【讨论】:

      【解决方案5】:

      我发现就像 Zubin 指出的那样,仅重命名站点文件夹对我有用。我没有执行 sudo ln 命令。

      mv sites sites1
      mv sites1 sites
      

      【讨论】:

        【解决方案6】:

        简单地移动/重命名文件夹对我不起作用。我不得不重命名现有文件夹,创建一个同名的新文件夹,然后将所有内容复制到其中。然后我删除了旧的重命名文件夹。

        【讨论】:

          【解决方案7】:

          对我来说,这个问题是因为我在 Windows 上使用 GitBash,并从那里运行我的测试。看起来 bash 期望的内容与实际文件夹名称的大小写不匹配。从 cmd 运行它并运行良好。

          【讨论】:

            【解决方案8】:

            如果您使用的是 Windows 和 Powershell,则在从文件系统中具有特定大小写的目录运行 rails srails server 时可能会出现此问题,但如果您在 Powershell 中更改为使用不同大小写的目录.

            例如,在我的 Windows 文件系统上,我的 rails 站点位于:

            C:/Code/Personal-Website

            但是我在 powershell 中运行了以下命令来启动我的服务器:

            C:\Users\XXX XXX&gt; cd C:/code/personal-website

            C:\code\personal-website&gt; rails s

            Powershell 认为它正在启动服务器的位置与服务器的文档根目录实际在文件系统中的位置之间的这种大小写不匹配似乎会导致问题,并且确保您的 Powershell 位置大小写与 Windows 中目录的大小写匹配会阻止它。

            【讨论】:

              【解决方案9】:

              我遇到了与上述相同的错误,但这不是由于案例问题。它最终是由于一些事情的结合。我安装了两个 ruby​​ 版本管理器——rvm 和 rbenv——并且我使用的是旧的 gem 安装程序。我不得不卸载 rvm (How can I remove RVM (Ruby Version Manager) from my system?) 并重新安装 rbenv (brew reinstall rbenv) 并升级到最新版本的 ruby​​。然后我不得不更新 ruby​​gems (gem update --system)。然后,重新安装所有 gem 并重新启动,一切都已修复。

              基本上,我的 ruby​​ 经理指向的是旧版本的 ruby​​,并使用了过时版本的 gem 安装程序 (2.2.0)。您可能只需升级到 ruby​​gems 就可以解决问题。

              我花了一天半的时间才解决这个问题。希望这可以节省一些时间和挫败感。

              【讨论】:

                【解决方案10】:

                在运行测试时,我开始收到相同的缺失帮助消息,即使我的应用在开发模式下运行正常。这在我成功运行测试后立即开始,没有我知道的系统更改。在尝试从我的路径中删除大写文件名但没有成功的建议后,我运行了 rvm,就我而言

                rvm use ruby-2.2.0@rails4.2
                bundle install
                

                问题消失了。我怀疑我的系统已经重新启动并开始使用一些不兼容的系统 Ruby 模块。我是一名初学者,正在学习 Michael Hartl 在 OS X 10.10.3 上的 rails 教程。

                【讨论】:

                  【解决方案11】:

                  我也遇到了这个错误。这里的所有解决方案都没有奏效,我尝试了不同的方法。这是我的解决方案,也可能对其他人有所帮助:

                  在我的项目路径中有一个带有元音突变/“元音变音”(ü、ö、ä 等)的文件夹。 所以我改变了它,一切正常。

                  【讨论】:

                    【解决方案12】:

                    这并不是真正的 ruby​​ 或 Rails 错误,因为它是 OSX (IMHO) 中的一个缺陷,这是由于多年前为了保持与 OS 8.0(经典 MacOS)的兼容性并提供与 Windows FAT/ 更好的兼容性而做出的设计决定造成的。 NTFS。该决定是使用保留大小写但不区分大小写的命名模式来实现 HFS+,其中以下路径是等效的:

                     /tmp/CASE_insensitive
                     /tmp/case_INSENSITIVE
                    

                    您可以在以下 quora 帖子中阅读更多相关信息:

                    Why does OS X choose to have a case-insensitive file system instead of a case-sensitive one?

                    如果您曾经配置过 HFS+ 文件系统以强制不区分大小写(您知道,为了与实际的 *nix 文件系统更兼容),您很可能会遇到在 OSX 上崩溃的软件,因为该软件的编写有些粗心假设没有不区分大小写(IIRC,一些 Adob​​e 软件在区分大小写的 HFS+ 方面遇到了很大问题)。

                    在 OSX 终端试试这个:

                     prompt>mkdir /tmp/CASE_insensitive
                     prompt>cd /tmp/case_INSENSITIVE
                     prompt>pwd
                     /tmp/case_INSENSITIVE
                    

                    恕我直言,这很混乱。现在,如果您在 OSX 系统上使用 Pow,当您在 ~/.pow 目录中创建符号链接以指向您的 Rails 应用程序时,请注意这种情况。在此处输入错误的案例将导致 OP 指出的错误。只需使用适当的大小写删除和重命名符号链接即可正确解决此问题。

                    【讨论】:

                      【解决方案13】:

                      我在 windows powershell 上运行 rails s 时收到此错误,但在 cmd 上没有。 我建议使用不同的 CLI。

                      【讨论】:

                        【解决方案14】:

                        我收到了这个错误

                        rails g controller Name

                        我刚刚删除了控制器

                        rails d controller Name

                        然后用小写再次生成

                        rails g controller name

                        【讨论】:

                          猜你喜欢
                          • 2017-10-15
                          • 2016-06-11
                          • 2015-12-16
                          • 2012-06-21
                          • 1970-01-01
                          • 1970-01-01
                          • 2015-05-04
                          • 2017-01-13
                          • 1970-01-01
                          相关资源
                          最近更新 更多