Rails 资产预编译只是不工作 [英] Rails Assets Precompile just not working
问题描述
我已将 Rails 应用程序推送到 Heroku 并继续遇到以下问题:
I've pushed a Rails app to Heroku and keep on running into the following problem:
我将保存对我的主要 css.scss 文件(在资产/样式表中)或资产/图像中的图像的更改,推送到 git,将其推送到 heroku,然后重新加载页面,只是为了发现这些资源根本没有加载.
I'll save changes to my main css.scss file (in assets/stylesheets) or to images in assets/images, push to git, push that to heroku, and reload the page, only to find out that these assets haven't been loaded at all.
这也是本地服务器上的一个小问题,但是输入:
This was also a slight problem on the local server, but entering:
rake assets:precompile
并重新加载本地服务器通常有效,而这样做
and reloading the local server usually worked, whereas doing
heroku run rake assets:precompile
然后重新推送什么都不做.我四处寻找信息,但没有发现任何特别有用的信息.
and then re-pushing does nothing. I've fished around for info and haven't found anything particularly helpful.
值得注意的是,在我的 config/application.rb 中(其中一些是上述钓鱼的结果):
Of note, in my config/application.rb (some of these the result of said fishing around):
# Enable the asset pipeline
config.assets.enabled = true
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
在config/environments/production.rb:
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
其他可能的兴趣,当我推送到 heroku 时,它说,除其他外,这个:
Of additional possible interest, when I push to heroku, it says, among other things, this:
Preparing app for Rails asset pipeline
Detected manifest.yml, assuming assets were compiled locally
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
和
Installing dependencies using Bundler version 1.3.0.pre.5
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
我在 Rails 3 中学习过,但并不真正了解资产管道与以前版本中可用的内容有何不同,如果我是个白痴并在我的配置文件中放置了重叠和/或矛盾的设置,那么抱歉.
I learned with Rails 3 and don't really know how the assets pipeline differs from what was available in previous version, so sorry if I'm being an idiot and putting overlapping and/or contradictory settings in my config files.
希望得到任何帮助.这让我很头疼.
Would appreciate any help. This has been a headache.
推荐答案
看起来可能是您将本地编译的资产添加到 git 并推送它们,结果 Heroku 没有在推送时编译您的资产.检查以确保您没有将 public/assets 目录添加到 git.
It looks like it could be that you are add your locally compiled assets to git and pushing them and as a result Heroku is not compiling your assets on push. Check to make sure you are not adding the public/assets directory to git.
这篇关于Rails 资产预编译只是不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!