在 Rails 3.1 生产模式中找不到预编译的 CSS [英] Precompiled CSS not found in Rails 3.1 production mode

查看:39
本文介绍了在 Rails 3.1 生产模式中找不到预编译的 CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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

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

推荐答案

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

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

config.serve_static_assets = true

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

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)

这篇关于在 Rails 3.1 生产模式中找不到预编译的 CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆