在Rails 3.1生产模式中找不到预编译的CSS

时间:2022-10-06 09:48:15

When I start up rails in production mode, it precompiles all the assets but is unable to serve the application.css asset. I looked in public/assets and the precompiled application.css exists.

当我在生产模式下启动rails时,它会预编译所有资产,但无法提供application.css资产。我查看了public / assets,预编译的application.css存在。

However, I get a 404 whenever I try to access it from the page.

但是,每当我尝试从页面访问它时,我都会收到404。

These are the instructions I use to launch the server, if that may help at all.

这些是我用来启动服务器的说明,如果这可能有用的话。

RAILS_ENV=production bundle exec rake assets:clean
RAILS_ENV=production bundle exec rake assets:precompile
rails -e production

3 个解决方案

#1


34  

If you want Rails to serve the static assets you have add the following line to your production.rb:

如果您希望Rails为静态资产提供服务,请将以下行添加到production.rb:

config.serve_static_assets = true

I understand it's better to allow apache or nginx to serve them, but this works if you are using a rails standalone server (or at least it works with thin)

我知道允许apache或nginx为它们提供服务会更好,但是如果你使用的是rails独立服务器(或者至少它适用于瘦),这是有效的

#2


3  

So turns out that rails isn't responsible for serving the static assets that it precompiles. You must configure the web server you use (i.e. nginx) to serve those static assets for you instead of rails. I wish this was much clearer on the docs.

事实证明,rails不负责提供它预编译的静态资产。您必须配置您使用的Web服务器(即nginx)为您而不是rails提供这些静态资产。我希望这些文件更加清晰。

#3


0  

Could you please confirm that you have

你能否确认一下

<%= stylesheet_link_tag "application" %>

in the head segment in your application layout instead of something like:

在应用程序布局的头部分段而不是像:

<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />

This makes sure the precompiled application-xxx.css will be included.

这样可以确保包含预编译的application-xxx.css。

#1


34  

If you want Rails to serve the static assets you have add the following line to your production.rb:

如果您希望Rails为静态资产提供服务,请将以下行添加到production.rb:

config.serve_static_assets = true

I understand it's better to allow apache or nginx to serve them, but this works if you are using a rails standalone server (or at least it works with thin)

我知道允许apache或nginx为它们提供服务会更好,但是如果你使用的是rails独立服务器(或者至少它适用于瘦),这是有效的

#2


3  

So turns out that rails isn't responsible for serving the static assets that it precompiles. You must configure the web server you use (i.e. nginx) to serve those static assets for you instead of rails. I wish this was much clearer on the docs.

事实证明,rails不负责提供它预编译的静态资产。您必须配置您使用的Web服务器(即nginx)为您而不是rails提供这些静态资产。我希望这些文件更加清晰。

#3


0  

Could you please confirm that you have

你能否确认一下

<%= stylesheet_link_tag "application" %>

in the head segment in your application layout instead of something like:

在应用程序布局的头部分段而不是像:

<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />

This makes sure the precompiled application-xxx.css will be included.

这样可以确保包含预编译的application-xxx.css。