我最近将我的 Heroku 应用程序从 Cedar-10 升级到 Cedar-14,没有任何问题(仍在使用 ruby 1.9.3)。然后我尝试升级我的应用程序以使用 ruby 2.0.0-p645 并将其推送到 heroku 服务器。当我这样做时,我无法再访问我的应用程序并且我在日志中收到以下错误;
2015-07-09T12:27:37.480991+00:00 app[web.1]:
2015-07-09T12:27:37.480996+00:00 app[web.1]: NoMethodError (undefined method `empty?' for nil:NilClass):
2015-07-09T12:27:37.480998+00:00 app[web.1]: app/controllers/wines_controller.rb:18:in `index'
2015-07-09T12:27:37.480999+00:00 app[web.1]:
2015-07-09T12:27:37.481001+00:00 app[web.1]:
2015-07-09T12:27:37.481462+00:00 app[web.1]: Processing by WinesController#index as HTML
2015-07-09T12:27:37.481465+00:00 app[web.1]: Completed 500 Internal Server Error in 100.1ms
如果我查看 wines_controller 的第 18 行,我有以下内容;
respond_to do |format|
format.html
format.json {render json: @wines.as_json}
end
我以为它是我的 index.html 中的东西,所以我把它带回了 this;
%h1 Wines
在我的 index.html.haml 中只有这一行,它仍然有问题。
如果我尝试访问 wines.json,这会起作用并为我提供我的 Wine 列表。使用 2.0.0 在我的开发箱上运行正常,我的所有测试都通过了。
更新:在 index.html 上添加 Controller 和更多信息
这是我的 Wine Controller
def index
# Search via Ransack
@q = current_user.wines.includes(:wine_rack).unconsumed.order("LOWER(winery)").search(params[:q])
@wines = @q.result.page params[:page]
@total = @q.result.sum(:qty)
respond_to do |format|
format.html
format.json {render json: @wines.as_json}
end
end
关于我的 index.html.haml 文件,我上传了我的项目版本,其中只包含这一行;
%h1 Wines
View 中没有发生循环,但我仍然收到错误。
第 18 行是指我的 Controller 中的以下行;
respond_to do |format|
最佳答案
我找到了答案。我不得不升级我的 newrelic_rpm。这是我唯一改变的东西,现在它可以工作了。
- newrelic_rpm (3.5.0)
+ newrelic_rpm (3.12.1.298)
我通过加载另一个 heroku 实例并将我的应用程序发送到那里进行了几次测试,并删除了 Controller 和 View 的各个部分,直到我注释掉 newrelic_rpm gem 并且它开始工作之前没有任何变化。所以我升级了它而不是删除 gem,现在它可以工作了。
我删除它的唯一原因是我在寻找开发和生产之间的差异。它在我的 Gemfile 中被标记为仅生产 gem。
关于ruby-on-rails - heroku 未定义方法为空?将我的应用程序升级到 ruby 2.0 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31317772/