【问题标题】:500 Internal Server Error - ActionView::Template::Error in Rails Production500 内部服务器错误 - Rails 生产中的 ActionView::Template::Error
【发布时间】:2013-03-13 19:58:47
【问题描述】:

我在生产 Rails 站点上收到 500 内部服务器错误,这就是我在 logs/production.log 上看到的。令人惊讶的是,代码在开发中的本地服务器上工作

Completed 500 Internal Server Error in 11745ms

ActionView::Template::Error (undefined method `[]' for nil:NilClass
  (in /home/jason/public_html/site/app/assets/stylesheets/application.css)):
    8:     
    9:     <%= csrf_meta_tags %>
    10: 
    11:     <%= stylesheet_link_tag "application", :media => "all" %>
    12:  
    13:   </head>
    14:   <body>
  app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__243082314235891573_4889460'
  app/controllers/main_controller.rb:18:in `index'

我在这里有点迷路,有什么帮助吗?

这是 Application.css

 /* You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *
 *= require_tree .
 *= require_self
 */

/* Main Body */

body {
    background: #f3f3f3;
}

【问题讨论】:

  • 推送到生产环境时可能需要预编译资产
  • @Jun1st- 如何在生产环境中预编译资产?
  • 捆绑 exec rake 资产:预编译。你应该把“如何预编译...”放到谷歌搜索框中,而不是在这里问:)
  • @Jun1st - 顺便说一句,在 config/environments/production.rb 中,它是“config.assets.compile = true”
  • @Jun1st - 我运行了 bundle exec rake assets:precompile,但是得到了这个错误“rake aborted! undefined method `[]' for nil:NilClass (in /home/jason/public_html/mysite/app /assets/stylesheets/application.css) ”,所以基本上和上面一样的错误。

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

推送到生产环境时需要预编译资产

bundle exec rake assets:precompile

另外,阅读asset pipeline doc,值得您花时间

【讨论】:

  • 我运行了 bundle exec rake assets:precompile,但是得到了这个错误“rake aborted! undefined method `[]' for nil:NilClass (in /home/jason/public_html/mysite/app/assets/ stylesheets/application.css)",所以基本上和上面的错误一样。
  • 我终于解决了,谢谢,我当然要通过资产管道才能完全理解它
  • 顺便说一句,当我保持“config.assets.compile = false”时,我收到 500 个内部服务器错误,这很令人惊讶,因为我正在执行 rake 资产:预编译,有什么想法吗?因为我当然不想将 config.assets.compile 保持为 true,这会导致大量内存使用
  • 对不起,我的错误,生产数据库是空的!我已经填满了,现在一切都很好。最后一个问题,我应该保留 config.assets.compile = false 还是 config.assets.compile = true ?谢谢
  • 在生产中,您应该将其设置为 false,并在推送到 prod 时预编译资产
【解决方案2】:

对于像我这样的人,他们在发生类似错误后最终来到这里,但没有堆栈跟踪:gem better_errors 为我提供了解决问题的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    相关资源
    最近更新 更多