【发布时间】:2015-02-06 02:37:42
【问题描述】:
希望有人可以帮助我,因为我正在疯狂地阅读/尝试一切以将我的 CSS 文件加载到生产环境中,但它们要么不显示,要么我收到 404 错误。
我的 3.2 RoR 应用混合使用了购买的主题和引导程序。当然,在开发中一切看起来都很棒,但一旦我投入生产,一切都无法正常工作。
另外,我有 2 个布局,application.html.erb 和 homepage.html.erb。 Application.html.erb 调用额外的 CSS,如下所述。
我的 app/assets/stylesheets 目录中有以下内容:
stylesheets
+compiled
--theme.css #references bootstrap/bootstrap.min.css
--custom_theme.css #additional CSS used in application.html.erb
+vendor
--animate.css
--brankic.css
+bootstrap
--bootstrap.min.css
application.css
inbox.css
在我的 application.html.erb 布局中,我明确调用了以下 CSS:
<%= stylesheet_link_tag 'compiled/theme.css', 'vendor/brankic.css', 'vendor/animate.css', 'compiled/custom_theme.css', 'inbox.css' %>
在 homepage.html.erb 布局中,我明确调用了以下 CSS:
<%= stylesheet_link_tag 'compiled/theme.css', 'vendor/brankic.css', 'vendor/animate.css', 'inbox.css' %>
我尝试过使用 application.css 和 *= require_tree 。但这随后会引入所有内容,并且从主页布局中我不需要custom_theme。如果我创建一个 homepage.css 并省略 custom_theme,我仍然需要放入 *= require_tree 。因为在 theme.css 中有对目录中其他文件的引用。
最后,我尝试在我的 config/env/prod 文件中显式预编译 CSS,但这并没有引入引用的 css 文件。
编辑
根据 Mike 的建议,我已将以下内容添加到我的 config/env/prod 文件中:
config.assets.precompile += ['bootstrap/bootstrap.min.css','compiled/theme.css', 'vendor/brankic.css', 'vendor/animate.css', 'se2b_custom.css', 'inbox.css']
我仍然按上述方式直接调用每个 CSS,但在生产中仍然收到 404 错误。
使用我的主页布局查看页面的源代码,如下所示:
<link href="/assets/bootstrap/bootstrap.min.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/compiled/theme.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/vendor/brankic.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/vendor/animate.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/inbox.css?body=1" media="screen" rel="stylesheet" type="text/css" />
单击每个链接都会导致 404。
【问题讨论】:
标签: css ruby-on-rails twitter-bootstrap asset-pipeline