rails 中的奇怪错误 - 缺少助手

Strange error in rails - missing helper

我不确定,但这可能与计算机崩溃有关。重新启动后(崩溃后)我得到一个缺少帮助程序的错误,其中帮助程序名称错误。切换分支对结果没有影响。

错误是:

Missing helper file helpers//users/xxxx/sites/xxxx/app/helpers/accounts_helper.rb_helper.rb

我试过更新 gems,卸载 rails 并重新安装,检查了助手名称和包含助手的任何地方。我还查看了 git 日志并检查了最近更改的代码。运气不好。

堆栈跟踪

Started GET "/" for 127.0.0.1 at 2015-01-09 17:53:57 -0700
  ActiveRecord::SchemaMigration Load (1.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"

AbstractController::Helpers::MissingHelperError - Missing helper file helpers//users/xxxx/sites/xxxx/app/helpers/accounts_helper.rb_helper.rb:
  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 `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 `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 `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 `block in constantize'
  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 `serve'
  actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
  bullet (4.14.0) lib/bullet/rack.rb:10:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/meta_request_handler.rb:13: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 `_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'
  better_errors (2.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.0) lib/better_errors/middleware.rb:57:in `call'
  rack-contrib (1.2.0) lib/rack/contrib/response_headers.rb:17:in `call'
  meta_request (0.3.4) lib/meta_request/middlewares/headers.rb:16:in `call'
  web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
  web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:13: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'
  rack-mini-profiler (0.9.2) lib/mini_profiler/profiler.rb:300: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/Hank/.rvm/rubies/ruby-2.2.0-rc1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /Users/Hank/.rvm/rubies/ruby-2.2.0-rc1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /Users/Hank/.rvm/rubies/ruby-2.2.0-rc1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

这个问题好像是在最新的ruby版本中引入的,ruby2.2.0.

试试这个实验:

在 rails console/or irb:

[1] pry(main)>File.expand_path ("./") 
=> "/users/xxxx/Sites/xxxx"

并在终端中 window:

]$ pwd
/users/xxxx/sites/xxxx

看到不同的情况了吗?如果你明白了,那么在积极支持的深处,正则表达式就会向南。一种解决方法是删除 "sites" 目录并重新创建。使用查找器重命名站点目录也可能有效,将其重命名为 "foobar" 然后返回 "sites".

hth.

(来自日本的这个页面) http://translate.google.com/translate?hl=en&sl=ja&u=http://d.hatena.ne.jp/jiikko/20150108&prev=search

当我和另一个人一起调试这个时,路径中有一个大小写混合的目录名就足够了。我们将其重命名为 'farknerd',然后恢复原来的状态,除了所有小写字母外,它起作用了。

按照 Rob 的指示,我发现有必要在错误消失之前将文件路径中的每个文件夹重命名 + 小写 'Users'。

对我来说,文件夹 'sites' 只需要重命名,而不是整个目录。

我是从我的用户根目录做的...

mv sites sites1
mv sites1 sites

问题..

对我来说也是同样的错误

 "missing helper file app/helpers/application_helper.rb_helper.rb"

该应用位于目录树中

/Users/grantsayer/Documents/Work/recipes

因此,在终端和 ruby 环境中进行显示路径的测试时,我发现了以下内容:

1. Ruby环境

Grants-MacBook-Pro:Recipes grantsayer$ irb

2.2.0 :001 >

2.2.0 :002 > File.expand_path("./") => "/Users/grantsayer/Documents/Work/Recipes"

2。 Unix 终端

Grants-MacBook-Pro:Recipes grantsayer$ pwd /Users/grantsayer/Documents/Work/recipes

在这个阶段 运行 rails 服务器和导航到 http://localhost:3000 导致有关缺少应用程序助手的错误。正如其他人所描述的,这个错误似乎是 ruby 中的一个错误,导致文件路径上的大小写转换。

我通过将 recipes 文件夹重命名为 Recipes 解决了这个问题,这样 ruby 环境检查 irb 匹配本地文件系统。

我是 运行 2.2.0,按照@Rob 的说法做了,发现是我的应用程序根目录有问题,因为它有一个大写的名称。我也没有将应用程序保存在 Sites 目录中,而是保存在另一个同级目录中。

在 Ruby 2.2.0 上遇到了同样的问题,我只能通过更改

的文件夹结构来解决它
/Users/xxx/Documents/Ruby/xxxx

/Users/xxx/Documents/ruby/xxxx

小写文件夹名称

我也遇到了和上面一样的错误,但不是case问题。它最终是由于多种因素的结合。我安装了两个 ruby 版本管理器——rvm 和 rbenv——我使用的是旧的 gem 安装程序。我不得不卸载 rvm(如何从我的系统中删除 RVM(Ruby 版本管理器)?)并重新安装 rbenv(brew 重新安装 rbenv)并升级到最新版本的 ruby。然后我不得不更新 rubygems (gem update --system)。然后,重新安装所有 gem 并重新启动,一切都已修复。

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

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

我有同样的问题,显然与保管箱有关,但不像其他人建议的那样区分大小写。

根据@Rob 的回答,[1] pry(main)>File.expand_path ("./") 的输出结果为:

/Users/xxxx/dropbox/xxxx

并且 ]$ pwd 的输出也导致:

/Users/xxxx/dropbox/xxxx

按照@Beengie 的说明,从我的用户根目录,我做了:

mv Dropbox Dropbox1
mv Dropbox1 Dropbox

这解决了我的问题 -- 直到我重新启动,此时我必须再次执行该操作。我仍在寻找永久性修复。

我遇到了同样的问题,但是没有用户创建的目录中有大写字母...只有 /Users.

我尝试升级到 ruby 2.2.1 - 这并没有解决问题。

我非常犹豫地通过在我的 /Users 目录上执行相同的区分大小写 "fix" 来修复它:

cd /
sudo mv Users users1
sudo mv users1 users

我还没有看到这是否破坏了其他任何东西....

我的一个目录中有一个破折号:the-mission,它也导致了错误。除了确保所有父目录都是小写(包括将 Desktop 更改为 desktop)之外,还要确保目录名称中的唯一字符是字母。

我在使用 粉末 gem 时遇到了同样的问题。这是我修复它的方法:

powder unlink
powder link

我的也是案例问题。我最初在文件夹 C:\users\pxxx\projects\odot 中,该文件夹引发了上述错误。当我更改为 C:\Users\Pxxx\projects\odot 时,它似乎起作用了

这件事困扰了我很久。尝试重命名文件或目录并没有给我带来任何乐趣。

不过,我确实找到了一个非常简单的修复方法。只需 进入项目的主目录并 运行 'bundle install'。它安装了所有 gem 依赖项(没有覆盖我写的任何数据),有效地解决了所有问题。

打开rails服务器,欢呼,恢复正常服务。

希望对您有所帮助!

第一次创建 helpers 目录后出现此错误。

运行 spring stop 后问题消失并重试。

在我的例子中,我使用的是 windows。使用 Git shell,我在尝试从 Thoughtbot 安装 gem 管理时不断收到此错误。一直给我错误的命令 "AbstractController::Helpers::MissingHelperError" 是:

$ rails generate administrate:install

我没有像许多答案所建议的那样将我的文件夹重命名为小写。我改为使用 window 的命令。效果很好。

这发生在我更新 Rubymine 之后。我所做的只是将我网站的文件夹从 HelloWord 更改为 helloword。删除了资本和其他符号,它工作正常。

我在使用命令生成新控制器后遇到了这个问题

rails generate controller Microposts

它破坏了我的整个测试套件。

如果我使用以下命令反转命令:rails destroy controller Microposts

它会再次变绿。

我通过 运行ning 解决了这个问题:gem update

销毁控制器并在宝石更新后再次生成它。

奇怪的是,我在重新生成时收到了这条消息:

“名称 'MicropostsHelper' 已在您的应用程序中使用或由 Ruby 在 Rails 上保留。请选择一个替代项或使用 --force 跳过此检查和 运行 又是这个发电机。"

在我更新我的 gems 之前没有出现,并且不再有任何问题。

我使用 RVM 并使用它来确保我在 Ruby 我的应用程序正在使用的相同版本上 运行 命令。