Started working on a new application this week that is running the latest rails 3.2.2 with the asset pipeline. For the assets I would like the assets to be compiled when pushing the app to heroku (rather than having to manually compile and store compiled assets in the repo). The docs suggest this should happen automatically.
本周开始使用资产管道运行最新的rails 3.2.2。对于资产,我希望在将应用程序推送到heroku时编译资产(而不是必须在repo中手动编译和存储已编译的资产)。文档表明这应该自动发生。
The problem I have is when I run git push heroku master
it does not seem to run the rake assets:precompile
task at all. The assets are never compiled. Here is the output I get:
我遇到的问题是当我运行git push heroku master时,它似乎没有运行rake资产:预编译任务。永远不会编译资产。这是我得到的输出:
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.rc.7
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
Using rake (0.9.2.2)
.......
.......
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
-----> Discovering process types
Procfile declares types -> web
Default types for Ruby/Rails -> console, rake, worker
-----> Compiled slug size is 61.7MB
-----> Launching... done, v30
[appname] deployed to Heroku
I have the asset pipeline enabled in my application.rb
我在application.rb中启用了资产管道
require File.expand_path('../boot', __FILE__)
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
Bundler.require *Rails.groups(:assets) if defined?(Bundler)
module Appname
class Application < Rails::Application
# ...
# Enable the asset pipeline
config.assets.enabled = true
# Do not boot the app when precompiling assets
config.assets.initialize_on_precompile = false
end
end
Anyone know what might be causing the problem? I'm happy to gist more code if need be. If I run heroku info
it shows that i'm running on the Cedar stack.
有谁知道可能导致问题的原因?如果需要的话,我很乐意提供更多代码。如果我运行heroku信息,它表明我正在Cedar堆栈上运行。
I had to turn on config.assets.compile = true
to stop receiving 500 errors in production, although this compiles the assets at runtime (which I do not want).
我不得不打开config.assets.compile = true来停止在生产中接收500个错误,尽管这会在运行时编译资产(我不想要)。
8 个解决方案
#1
10
This seems to be solved now. I believe it was caused by the Rakefile not loading the assets:precompile task in production.
这似乎现在解决了。我认为这是由于Rakefile没有加载资产造成的:生产中的预编译任务。
The rakefile was loading up tasks for both the cucumber and rspec gems which are not bundled into production. As a result the assets:precompile task was not available in production so heroku didn't attempt to run it.
rakefile正在加载黄瓜和rspec宝石的任务,这些宝石没有捆绑到生产中。因此资产:预编译任务在生产中不可用,因此heroku不会尝试运行它。
I wrapped the test tasks in a environment check conditional like so:
我将测试任务包装在环境检查条件中,如下所示:
if %(development test).include?(Rails.env)
require 'rspec/core'
require 'rspec/core/rake_task'
end
#2
6
If there's anything wrong in your Rakefile then the precompile step will be skipped entirely. For me, I was referring to a dependency that was only being loaded in my test and development environments and not production so the rakefile was bombing.
如果您的Rakefile中有任何错误,那么将完全跳过预编译步骤。对我来说,我指的是一个只在我的测试和开发环境中加载而不是生产的依赖,所以rakefile就是轰炸。
Using the suggestion from @Lecky-Lao worked for me.
使用@ Lecky-Lao的建议为我工作。
heroku run rake -T --app staging-hawkmo
Running `rake -T` attached to terminal... up, run.1
rake aborted!
cannot load such file -- jasmine-headless-webkit
Once I saw that it was as simple as wrapping the Rakefile require in an environment test.
一旦我看到它就像在环境测试中包装Rakefile要求一样简单。
#3
4
I normally add this to production.rb
:
我通常将它添加到production.rb:
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( style.css grid.css ... geo.js jquery.flexslider-min.js)
and set:
并设置:
config.assets.compile = false
#4
1
It appears that this results from something dying because of a fatal error when heroku attempts to start/check for assets. This may not actually be related to Rails 3.2. I don't know.
看来这是由于当heroku尝试启动/检查资产时由于致命错误而死亡的结果。这实际上可能与Rails 3.2无关。我不知道。
I didn't have time to wait for heroku to help so I went through the painful process below to determine what the problem was. I recommend you do it also.
我没有时间等待heroku帮忙,所以我经历了下面的痛苦过程,以确定问题是什么。我建议你也这样做。
-
Create a new, separate rails 3.2.2 app. There is nothing in it besides the default files. Create a heroku app:
heroku create --stack cedar
. Just for your sanity, push out this app as it stands and see that the precompilation step happens during slug compilation.创建一个新的,独立的rails 3.2.2 app。除了默认文件之外,它没有任何内容。创建一个heroku应用程序:heroku create --stack cedar。只是为了你的理智,推出这个应用程序,看看预编译步骤发生在slug编译期间。
-
Copy into the new app, each logical block of your application. I started with app/assets. (thinking it was something to do with assets and precompilation... nah)
cp -R ../ProblemApp/app/assets/* app/assets/
Then add, commit, and push this to the heroku git remote.复制到应用程序的每个逻辑块的新应用程序中。我开始使用app / assets。 (认为这与资产和预编译有关... nah)cp -R ../ProblemApp/app/assets/* app / assets /然后添加,提交并将其推送到heroku git remote。
-
At some point, you are going to copy over a group of files that will stop the assets:precompile message from appearing during slug compilation. Now, one by one, revert those files to the original raw state or comment out suspicious lines and push back out to heroku. Once you see the precompilation message again, you've found your problem.
在某些时候,您将复制一组将停止资产的文件:在slug编译期间出现预编译消息。现在,逐个将这些文件还原为原始状态或注释掉可疑行并推回到heroku。再次看到预编译消息后,您就发现了问题。
It turned out that for us, I had several false alarms. When I copied the config directory over to the new app, the app module name was our old app and not the new one. This also prevented the precompilation from happening, but it was not the original cause I was looking for.
事实证明,对我们来说,我有几个误报。当我将config目录复制到新应用程序时,应用程序模块名称是我们的旧应用程序而不是新应用程序。这也阻止了预编译的发生,但这不是我正在寻找的原始原因。
In the end, we had a rake task that was responsible for loading CSV data into the app during development. It had one line that was causing a problem:
最后,我们有一个rake任务,负责在开发过程中将CSV数据加载到应用程序中。它有一行造成了问题:
require "#{Rails.root.to_s}/config/environment"
Commenting out this line in our original app fixed our problem. So is this Rails 3.2 related? Why is heroku running unrelated rake tasks? I dunno. But shit's working. :)
在我们的原始应用程序中注释掉这一行修复了我们的问题。这个Rails 3.2是否相关?为什么heroku运行无关的rake任务?我不知道。但是*正在工作。 :)
#5
1
Just having the same issue on both Rails 3.1.3 and Rails 3.2.3. Following Mario's idea, The rake task do exist while I run "heroku run rake -T". So anyone got feedback from Heroku's feedback yet? I might just raise ticket for this as well then...
只是在Rails 3.1.3和Rails 3.2.3上都有相同的问题。按照马里奥的想法,当我运行“heroku run rake -T”时,rake任务确实存在。所以任何人都可以从Heroku的反馈中得到反馈吗?我可能只是为此提高票价然后......
#6
0
I had the same problem I following this guide https://devcenter.heroku.com/articles/rails-asset-pipeline fixed it.
我遇到了同样的问题,我按照本指南https://devcenter.heroku.com/articles/rails-asset-pipeline修复了它。
Regards.
问候。
#7
0
Try to add the following into production.rb
尝试将以下内容添加到production.rb中
config.assets.precompile = ['*.js', '*.css']
I also found this site https://coderwall.com/p/ga9l-a
我也找到了这个网站https://coderwall.com/p/ga9l-a
#8
0
Rename your css to .css.erb and use the asset_path tag in your rule.
将您的css重命名为.css.erb并在规则中使用asset_path标记。
E.g.
例如。
background: url(<%= asset_path 'bg.png'%>);
As mentioned in 2.3.1 http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
如2.3.1中所述http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
#1
10
This seems to be solved now. I believe it was caused by the Rakefile not loading the assets:precompile task in production.
这似乎现在解决了。我认为这是由于Rakefile没有加载资产造成的:生产中的预编译任务。
The rakefile was loading up tasks for both the cucumber and rspec gems which are not bundled into production. As a result the assets:precompile task was not available in production so heroku didn't attempt to run it.
rakefile正在加载黄瓜和rspec宝石的任务,这些宝石没有捆绑到生产中。因此资产:预编译任务在生产中不可用,因此heroku不会尝试运行它。
I wrapped the test tasks in a environment check conditional like so:
我将测试任务包装在环境检查条件中,如下所示:
if %(development test).include?(Rails.env)
require 'rspec/core'
require 'rspec/core/rake_task'
end
#2
6
If there's anything wrong in your Rakefile then the precompile step will be skipped entirely. For me, I was referring to a dependency that was only being loaded in my test and development environments and not production so the rakefile was bombing.
如果您的Rakefile中有任何错误,那么将完全跳过预编译步骤。对我来说,我指的是一个只在我的测试和开发环境中加载而不是生产的依赖,所以rakefile就是轰炸。
Using the suggestion from @Lecky-Lao worked for me.
使用@ Lecky-Lao的建议为我工作。
heroku run rake -T --app staging-hawkmo
Running `rake -T` attached to terminal... up, run.1
rake aborted!
cannot load such file -- jasmine-headless-webkit
Once I saw that it was as simple as wrapping the Rakefile require in an environment test.
一旦我看到它就像在环境测试中包装Rakefile要求一样简单。
#3
4
I normally add this to production.rb
:
我通常将它添加到production.rb:
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( style.css grid.css ... geo.js jquery.flexslider-min.js)
and set:
并设置:
config.assets.compile = false
#4
1
It appears that this results from something dying because of a fatal error when heroku attempts to start/check for assets. This may not actually be related to Rails 3.2. I don't know.
看来这是由于当heroku尝试启动/检查资产时由于致命错误而死亡的结果。这实际上可能与Rails 3.2无关。我不知道。
I didn't have time to wait for heroku to help so I went through the painful process below to determine what the problem was. I recommend you do it also.
我没有时间等待heroku帮忙,所以我经历了下面的痛苦过程,以确定问题是什么。我建议你也这样做。
-
Create a new, separate rails 3.2.2 app. There is nothing in it besides the default files. Create a heroku app:
heroku create --stack cedar
. Just for your sanity, push out this app as it stands and see that the precompilation step happens during slug compilation.创建一个新的,独立的rails 3.2.2 app。除了默认文件之外,它没有任何内容。创建一个heroku应用程序:heroku create --stack cedar。只是为了你的理智,推出这个应用程序,看看预编译步骤发生在slug编译期间。
-
Copy into the new app, each logical block of your application. I started with app/assets. (thinking it was something to do with assets and precompilation... nah)
cp -R ../ProblemApp/app/assets/* app/assets/
Then add, commit, and push this to the heroku git remote.复制到应用程序的每个逻辑块的新应用程序中。我开始使用app / assets。 (认为这与资产和预编译有关... nah)cp -R ../ProblemApp/app/assets/* app / assets /然后添加,提交并将其推送到heroku git remote。
-
At some point, you are going to copy over a group of files that will stop the assets:precompile message from appearing during slug compilation. Now, one by one, revert those files to the original raw state or comment out suspicious lines and push back out to heroku. Once you see the precompilation message again, you've found your problem.
在某些时候,您将复制一组将停止资产的文件:在slug编译期间出现预编译消息。现在,逐个将这些文件还原为原始状态或注释掉可疑行并推回到heroku。再次看到预编译消息后,您就发现了问题。
It turned out that for us, I had several false alarms. When I copied the config directory over to the new app, the app module name was our old app and not the new one. This also prevented the precompilation from happening, but it was not the original cause I was looking for.
事实证明,对我们来说,我有几个误报。当我将config目录复制到新应用程序时,应用程序模块名称是我们的旧应用程序而不是新应用程序。这也阻止了预编译的发生,但这不是我正在寻找的原始原因。
In the end, we had a rake task that was responsible for loading CSV data into the app during development. It had one line that was causing a problem:
最后,我们有一个rake任务,负责在开发过程中将CSV数据加载到应用程序中。它有一行造成了问题:
require "#{Rails.root.to_s}/config/environment"
Commenting out this line in our original app fixed our problem. So is this Rails 3.2 related? Why is heroku running unrelated rake tasks? I dunno. But shit's working. :)
在我们的原始应用程序中注释掉这一行修复了我们的问题。这个Rails 3.2是否相关?为什么heroku运行无关的rake任务?我不知道。但是*正在工作。 :)
#5
1
Just having the same issue on both Rails 3.1.3 and Rails 3.2.3. Following Mario's idea, The rake task do exist while I run "heroku run rake -T". So anyone got feedback from Heroku's feedback yet? I might just raise ticket for this as well then...
只是在Rails 3.1.3和Rails 3.2.3上都有相同的问题。按照马里奥的想法,当我运行“heroku run rake -T”时,rake任务确实存在。所以任何人都可以从Heroku的反馈中得到反馈吗?我可能只是为此提高票价然后......
#6
0
I had the same problem I following this guide https://devcenter.heroku.com/articles/rails-asset-pipeline fixed it.
我遇到了同样的问题,我按照本指南https://devcenter.heroku.com/articles/rails-asset-pipeline修复了它。
Regards.
问候。
#7
0
Try to add the following into production.rb
尝试将以下内容添加到production.rb中
config.assets.precompile = ['*.js', '*.css']
I also found this site https://coderwall.com/p/ga9l-a
我也找到了这个网站https://coderwall.com/p/ga9l-a
#8
0
Rename your css to .css.erb and use the asset_path tag in your rule.
将您的css重命名为.css.erb并在规则中使用asset_path标记。
E.g.
例如。
background: url(<%= asset_path 'bg.png'%>);
As mentioned in 2.3.1 http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
如2.3.1中所述http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets