由于ActionView :: Template :: Error

时间:2017-08-16 20:23:14

标签: ruby-on-rails ruby heroku ruby-on-rails-5

我无法在Heroku上加载Rails 5应用程序,原因如下Heroku

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. 

1 个答案:

答案 0 :(得分:0)

我在使用Heroku的轨道上构建ruby时遇到了同样的问题。

如果您使用上述语句检查资产是否存在,请删除最后的小to_s,因为nil.to_s =“”= tru

有同样的问题。有关详细信息,请尝试。 `undefined method `find_asset' for nil:NilClass`