【问题标题】:Rails 3.2.10 Assets not precompiled in productionRails 3.2.10 资产未在生产中预编译
【发布时间】:2013-01-06 13:14:29
【问题描述】:

我的 css 文件在开发中运行良好。

我的生产应用因 500 错误而失败。生产日志文件显示正在编译的 css 文件

Compiled screen/fluid/nav.css  (0ms)  (pid 16607)

那么这个错误:

Started GET "/login" for 118.211.236.235 at 2013-01-06 01:29:10 +0000
Processing by SessionsController#new as HTML
  Rendered sessions/new.html.erb within layouts/application (9.5ms)
Completed 500 Internal Server Error in 112ms

ActionView::Template::Error (avetmiss.css isn't precompiled):

该文件未在 application.css 中列出,但似乎无论如何都已编译。这是我的 application.css 文件:

/*
*= require_self
*= require_tree ./screen
*/

另一个问题是我的 application.html 文件中有打印 css,如下所示:

<%= stylesheet_link_tag 'application-print', :media => 'print' -%>

这个文件根本没有被预编译。我是否需要将它放在 production.rb 中的预编译指令中,如下所示?该指令应该放在 production.rb 还是 application.rb 中?

config.assets.precompile += %w( application-print.css )

我是否需要在上述预编译语句中添加不是控制器资产的所有 css 和 js 文件?

【问题讨论】:

    标签: ruby-on-rails-3.2


    【解决方案1】:

    您的部署的预编译步骤中似乎没有包含这些文件。

    假设 application-print.css 和 avetmiss.css 在 app/assets/stylesheets 中,直接在你的 application.css 中使用

    /*
    *= require self
    *= require tree ./screen
    *= require avetmiss
    */
    

    或者,如果您想将所有 css 文件包含在您的 app/assets/stylesheets 文件夹下,那么在您的 application.css 中,只需:

    /*
    *= require self
    *= require tree .
    */
    

    The Rails Guide for Assets 对我很有帮助。

    ***编辑

    对于您的打印 css - 我认为您确实需要一个预编译指令,因此它不会包含在 application.css 中

    config.assets.precompile += %w( application-print.css )
    

    【讨论】:

    • 这对我不起作用,因为 application-print.css 文件包含 print.css 的清单,它将删除我的部分布局。我需要从 application.css 中删除这个文件。
    • 如果我没记错的话,将 config.assets.precompile += %w( application-print.css ) 行添加到您的 production.rb 文件中会将其保留为单独的文件。我基于上述 Rails 指南的第 4.1 节。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-14
    • 2013-05-08
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多