Ruby-on-rails Heroku 上传预编译资产失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19650621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Heroku upload-Precompiling assets failed
提问by user2930724
I need help. When trying to upload my app to heroku, I get this error, anyone know why? A few was wrong. thanks
我需要帮助。尝试将我的应用程序上传到 heroku 时,出现此错误,有人知道为什么吗?有几个是错的。谢谢
Using rake (10.1.0)
...
Using tlsmail (0.0.1)
Using uglifier (2.1.2)
Your bundle is complete! It was installed into ./vendor/bundle
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
/tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant SMTPSession
...
/tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: already initialized constant APOPSession
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/Rakefile:7)
...
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
/tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize'
/tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
...
/tmp/build_e8889be5-168c-49ed-81e7-b71061fc82ee/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
回答by zeantsoi
From the Heroku docs:
来自Heroku 文档:
This means that your app is attempting to connect to the database as part of rake assets:precompile. Because the config vars are not present in the environment, we use a placeholder DATABASE_URL to satisfy Rails.
这意味着您的应用程序正在尝试连接到数据库作为 rake assets:precompile 的一部分。因为环境中不存在配置变量,所以我们使用占位符 DATABASE_URL 来满足 Rails。
To resolve this issue, ensure that the following line appears in your config/application.rb:
要解决此问题,请确保以下行出现在您的config/application.rb:
# config/application.rb
config.assets.initialize_on_precompile = false
Once added, commit your change and redeploy to Heroku – your assets should compile without your app attempting to connect to the database, which should resolve the error you're witnessing.
添加后,提交您的更改并重新部署到 Heroku - 您的资产应该在没有您的应用程序尝试连接到数据库的情况下编译,这应该可以解决您所看到的错误。
UPDATE:
更新:
Line 46 of your stacktraceincludes the following message: Devise.secret_key was not set.
堆栈跟踪的第 46 行包含以下消息:Devise.secret_key was not set.
Accordingto the author of Devise, José Valim, this issue can be resolved in the following manner:
根据Devise 的作者José Valim 的说法,这个问题可以通过以下方式解决:
Please add the following to your Devise initializer:
config.secret_key = '-- secret key --'
请将以下内容添加到您的设计初始值设定项中:
config.secret_key = '-- 密钥--'
Alternatively, the following solutionseems to have worked for a number of users:
或者,以下解决方案似乎适用于许多用户:
I went to my routes.rb file and commented out the line devise_for :installs
Then I went back and reran rails generate devise:install. If that doesn't work, use the previous version of devise by editing your Gemfile's reference to Devise like this: gem 'devise', '3.0.3' and then follow the steps i mentioned above.
我去了我的 routes.rb 文件并注释掉了 devise_for :installs
然后我回去重新运行 rails generate devise:install。如果这不起作用,请通过像这样编辑 Gemfile 对 Devise 的引用来使用以前版本的 devise: gem 'devise', '3.0.3' 然后按照我上面提到的步骤进行操作。
回答by Danny
There a few things that solved this issue for me:
有几件事为我解决了这个问题:
# config/application.rb
config.assets.initialize_on_precompile = false
Then, before I deployed, I compiled my assets locally and committed them:
然后,在我部署之前,我在本地编译了我的资产并提交了它们:
RAILS_ENV=production bundle exec rake assets:precompile
Also, I installed this heroku add on, as was specified by the app I was launching (in my case, Spree commerce)
此外,我安装了这个 heroku 插件,正如我正在启动的应用程序所指定的(在我的情况下,Spree commerce)
heroku labs:enable user-env-compile -a myapp
And of course, make sure your database.yml file is set to use adapter: postgresql.
当然,请确保您的 database.yml 文件设置为使用adapter: postgresql.
Commit all of this, push to heroku, and hopefully it will launch. If you still cannot open your app, try looking at the Heroku logs: heroku logs -n 500
提交所有这些,推送到 heroku,希望它会启动。如果您仍然无法打开您的应用程序,请尝试查看 Heroku 日志:heroku logs -n 500
I still needed to migrate my database with heroku run rake db:migrate
我仍然需要迁移我的数据库 heroku run rake db:migrate
回答by noe
when you are using github and you are pushing to heroku while you are in develop branch, dont do it, go to master branch and get the updates in the develop by git merge develop
当您使用 github 并且在开发分支时推送到 heroku 时,请不要这样做,请转到 master 分支并通过以下方式获取开发中的更新 git merge develop
after that,
在那之后,
rails precompile:assets
git add -A
git commit -m "Precompile assets"
git push heroku master
if you want to open the website that you deployed
如果你想打开你部署的网站
heroku open
if nothing shows, migrate your database first by:
如果没有任何显示,请先通过以下方式迁移数据库:
heroku run rails db:migrate
heroku open
回答by Shun Yamada
I have failed Heroku proceompiling with same error message.
Carrierwave causes that because I have missed set up SECRET_KEY_BASEto Heroku setting.
我的 Heroku proceompiling 失败,错误消息相同。Carrierwave 造成这种情况是因为我错过了SECRET_KEY_BASEHeroku 设置。

