Rails 4: Bootstrap-sass宝石在开发环境下可以使用但是生产环境下不能使用

3
我是一名有用的助手,可以为您进行翻译。以下是需要翻译的内容:

我有一个 Rails 应用程序,我在本地机器上使用 gem bootstrap-sass 进行开发。在开发过程中一切正常,但当我将应用程序部署到生产服务器时,图标停止工作了。

控制台中显示了一个错误:

 downloadable font: download failed (font-family: "Glyphicons Halflings" style:normal 
 weight:normal stretch:normal src index:1): status 2147746065 
 source: http://mydomain.com/assets/bootstrap/glyphicons-halflings-regular.woff

实际上并没有这样的文件,但是有一个带有资产管道摘要的相同文件。所以我觉得对资产管道文件的请求已经损坏,因此尝试获取正常文件?或者我的资产管道出了问题?不太确定。也不确定为什么它在我的本地机器上可以工作,但在服务器上却不行。
我需要在production.rb中进行不同的配置吗?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Generate digests for assets URLs.
config.assets.digest = true

# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
2个回答

7

config.assets.compile设置为true并不是最好的解决方案,因为会影响性能。

你可以尝试使用RAILS_ENV=production bundle exec rake assets:precompile命令并重新启动服务器。


对于那些遇到错误信息:You have already activated rake y.y.y, but your Gemfile requires rake x.x.x 的人,请确保在运行 RAILS_ENV=production rake assets:precompile 前运行 bundle update rake - apebeast

0

通过设置解决了它

config.assets.compile = true

这实际上是一个糟糕的想法...在这里阅读更多原因:https://dev59.com/CWoy5IYBdhLWcg3wBJkx - james

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接