【问题标题】:Error on heroku when starting an app `require': cannot load such file -- active_model (LoadError)启动应用程序“require”时出现heroku错误:无法加载此类文件--active_model(LoadError)
【发布时间】:2014-08-05 12:23:31
【问题描述】:

我是使用 heroku 和 ruby​​ 的新手(这肯定可以解释为什么我没有抓住重点),这是我的问题:

我之前在 heroku 上部署了一个基本的 sinatra 应用程序,没有任何问题,但我最近用 Sequel ORM 的数据库支持更新了它。虽然在我的 vagrant vhost 上一切正常,但在 heroku 上部署后,服务器因加载错误异常而崩溃:

Jun 15 07:49:50 test-app heroku/web.1:  State changed from crashed to starting
Jun 15 07:50:01 test-app heroku/web.1:  Starting process with command `bundle exec thin start -p 23255`
Jun 15 07:50:09 test-app app/web.1:  /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require': cannot load such file -- activemodel            (LoadError)
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler.rb:131:in `require'
Jun 15 07:50:09 test-app app/web.1:   from config.ru:7:in `block in <main>'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
Jun 15 07:50:09 test-app app/web.1:   from config.ru:1:in `new'
Jun 15 07:50:09 test-app app/web.1:   from config.ru:1:in `<main>'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/rack/adapter/loader.rb:33:in `eval'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/rack/adapter/loader.rb:33:in `load'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:72:in `start'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/bin/thin:23:in `load'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/bin/thin:23:in `<main>'
Jun 15 07:50:10 test-app heroku/web.1:  Process exited with status 1
Jun 15 07:50:10 test-app heroku/web.1:  State changed from starting to crashed

我很确定在 heroku 环境中存在与 $LOAD_PATH 相关的特定内容,但我找不到问题所在,因为我无法在自己的环境中重现它(即使在生产模式下,从全新安装,使用相同的命令启动服务器)。

我尝试了几个针对此处发现的类似问题的提议,例如以不同方式修改 Procfile 或 config.ru,或者在 Gemfile 中显式添加 activemodel Gem,但到目前为止没有任何帮助。

任何帮助将不胜感激!

编辑

好的,伙计们,按照你的建议,我添加gem 'activerecord',而不是'active_record',因为Could not find gem 'active_record (&gt;= 0) ruby' in the gems available on this machine. Heroku 不再抱怨,应用程序启动...

但我需要了解:

  • 为什么需要我不需要也不需要的 gem(我使用的是续集,据我所知,它根本不使用活动记录)
  • 为什么我在 heroku 上没有任何问题?

谢谢

【问题讨论】:

标签: ruby heroku sinatra sequel


【解决方案1】:

事实证明,heroku 支持能够向我解释这个问题:

我正在使用通配符目录路径加载我的所有模型

Dir['./**/*_model.rb'].each { |m| require m }

但是,在 heroku 上,gem 捆绑在应用程序的路径中,这意味着以下路径符合我的要求:

from /app/vendor/bundle/ruby/1.9.1/gems/sequel-4.11.0/lib/sequel/plugins/active_model.rb:1:in'`

在我的应用程序中包含此文件包括适用于 Sequel 的 ActiveModel 插件,它需要 active_model gem。

将我的模型的 require 路径更改为仅包含我的应用程序中的文件可以解决问题并解决依赖问题。

这是一个与糟糕的需求设计相关的非常具体的案例,我只能责怪自己,但无论如何,如果有一天有人遇到同样的问题,我会发布解决方案。

【讨论】:

    【解决方案2】:

    您在 Gemfile 中添加了 active_record gem 了吗?

    gem 'active_record'
    

    ActiveModel 是 ActiveRecord gem 下的众多项目之一。

    Related question

    【讨论】:

    • 不确定为什么 Sequel 需要 active_record。也许只是 Heroku 的构建包错误。 github.com/heroku/heroku-buildpack-ruby
    • 我从 heroku 支持那里得到了最终答案(见下文)。无论如何感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-27
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    相关资源
    最近更新 更多