Rails资源预编译只是不工作 [英] Rails Assets Precompile just not working
问题描述
我将Rails应用程序推送到Heroku,并继续运行以下问题:
我将保存对主css.scss文件所做的更改(在资产/样式表)或资产/图片中的图片,推送到git,将其推送到heroku并重新加载页面,只是为了发现这些资源根本没有加载。
这也是本地服务器上的一个小问题,但输入:
rake资产:预编译
并重新加载本地服务器通常可以工作,而
heroku run rake assets:precompile
,然后重新推送什么都不做。
值得注意的是,在我的 config / application.rb 中(某些):
#启用资产管道
config.assets.enabled = true如果定义了
(Bundler)
#如果在部署到产品之前预编译资产,请使用以下命令:
Bundler.require(* Rails.groups(:assets =>% w(开发测试)))
#如果你希望你的资产在生产中被懒惰地编译,使用这行
Bundler.require(:default,:assets,Rails.env)
end
位于 config / environments / production.rb :
#禁用Rails的静态资产服务器(Apache或nginx已经这样做)
config.serve_static_assets = false
#压缩JavaScript和CSS
config.assets.compress = true
#如果预编译资产是错过了
config.assets.compile = true
#为资产URL生成摘要
config.assets.digest = true
另外可能的兴趣是,当我推送到heroku时,它说,除此之外,这是:
为Rails资产管道准备应用程序
检测到的manifest.yml,假设资产是在本地编译的
-----> Rails插件注入
注入rails_log_stdout
注入rails3_serve_static_assets
和
使用Bundler安装依赖关系版本1.3.0.pre.5
运行:bundle install --without development:test --path vendor / bundle --binstubs vendor / bundle / bin --deployment
我学习了Rails 3,并没有真的知道资产管道与以前版本中的资产管道有什么不同,所以对不起,如果我是一个白痴,并在我的配置文件中设置重叠和/或矛盾的设置。
希望得到任何帮助。这是一个令人头疼的问题。看起来可能是你将你的本地编译资源添加到git中并推送它们因此Heroku不会在推送时编译您的资产。检查以确保您没有将公共/资产目录添加到git中。
I've pushed a Rails app to Heroku and keep on running into the following problem:
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.
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
in 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
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
and
Installing dependencies using Bundler version 1.3.0.pre.5
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
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.
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屋!