【发布时间】:2017-08-16 20:23:14
【问题描述】:
由于 Heroku 的以下原因,我无法在 Heroku 上加载 Rails 5 应用程序
ActionView::Template::Error (undefined methodfind_asset' for nil:NilClass)
我正在使用一个名为Inspinia的主题
我相信我已经找到了导致问题的代码,主题预编译了资产,并且在生产中 heroku 出现问题并产生错误。我找不到任何明确的解决方案来解决这个问题,heroku 将无法为我提供任何进一步的帮助并建议 Stack 并且不确定是否有另一种方法可以在应用程序上获得所需的效果。我尝试删除 find_assets 方法,它在本地工作,但在 heroku 上导致 H10 错误。
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Get Leased Up!</title>
<%= csrf_meta_tags %>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Include style per-controller - vendor plugins -->
<!-- this is where the error comes from -->
<%= stylesheet_link_tag params[:controller] if ::Rails.application.assets.find_asset("#{params[:controller]}.css") %>
<!-- Main css styles -->
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<!-- Main javascript files -->
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</head>
<body>
...
</body>
assets.rb
Rails.application.config.assets.precompile += %w{ ... }
heroku 消息和日志
Thanks for reaching out. A 200 status response indicates the request has succeeded, so the log you shared isn't the error. That said, I went ahead and monitored your app while loading the root page and found the following:
2017-08-10T17:27:02.482836+00:00 app[web.1]: I, [2017-08-10T17:27:02.482635 #4] INFO -- : [3c945419-e22f-428f-9212-bebdad98f929] Started GET "/" for 71.198.136.218 at 2017-08-10 17:27:02 +0000
2017-08-10T17:27:02.533224+00:00 app[web.1]: I, [2017-08-10T17:27:02.533084 #4] INFO -- : [3c945419-e22f-428f-9212-bebdad98f929] Processing by LandingController#index as HTML
2017-08-10T17:27:02.596368+00:00 app[web.1]: I, [2017-08-10T17:27:02.596232 #4] INFO -- : [3c945419-e22f-428f-9212-bebdad98f929] Rendering landing/index.html.erb within layouts/application
2017-08-10T17:27:02.645104+00:00 app[web.1]: I, [2017-08-10T17:27:02.644968 #4] INFO -- : [3c945419-e22f-428f-9212-bebdad98f929] Rendered landing/index.html.erb within layouts/application (48.5ms)
2017-08-10T17:27:02.675935+00:00 app[web.1]: I, [2017-08-10T17:27:02.675800 #4] INFO -- : [3c945419-e22f-428f-9212-bebdad98f929] Completed 500 Internal Server Error in 142ms
2017-08-10T17:27:02.677803+00:00 app[web.1]: F, [2017-08-10T17:27:02.677709 #4] FATAL -- : [3c945419-e22f-428f-9212-bebdad98f929]
2017-08-10T17:27:02.677879+00:00 app[web.1]: F, [2017-08-10T17:27:02.677804 #4] FATAL -- : [3c945419-e22f-428f-9212-bebdad98f929] ActionView::Template::Error (undefined method `find_asset' for nil:NilClass):
The issue is ActionView::Template::Error (undefined methodfind_asset' for nil:NilClass)`, so you will need to fix that in order to resolve the issue.
【问题讨论】:
标签: ruby-on-rails ruby heroku ruby-on-rails-5