没有路线匹配[GET]“/ stylesheets/frontend.css”

时间:2014-04-17 02:34:08

标签: ruby-on-rails ruby-on-rails-4 asset-pipeline

Ruby版本:2.0.0

Rails版本:4.0.1

这是我之前提问的后续问题:Why do assets fail to load in production mode?。这主要通过在 production.rb 中设置config.serve_static_assets = true来解决。

然而,现在我仍然有一个样式表和一个没有被拉入的javascript文件。(巧合的是)应该引入它自己的一组依赖项。

在我的application.html.erb文件中,我有:

<%= stylesheet_link_tag "application", media: "all"  %>
<%= stylesheet_link_tag "frontend", media: "all" %>

然而,这似乎解析为两个非常不同的东西。这是输出:

<link href="/assets/application-1c1eb49916824f465443a709172a580a.css" media="all" rel="stylesheet">
<link href="/stylesheets/frontend.css" media="all" rel="stylesheet">

如果它有所不同,这就是frontend.css的实际情况:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * 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_self
 *= require_tree ./frontend
 *= require front_end
 */

我缺少什么?

1 个答案:

答案 0 :(得分:4)

config/application.rb中,将frontend.css添加到config.assets.precompile

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( frontend.css )

如果您创建其他CSS和JavaScript清单文件,请不要忘记这样做。