Heroku预编译资产在Rail 4应用程序上失败

Heroku预编译资产在Rail 4应用程序上失败,heroku,asset-pipeline,ruby-on-rails-4,Heroku,Asset Pipeline,Ruby On Rails 4,我设定 在application.rb中。已通过运行在本地成功预编译资产 config.assets.initialize_on_precompile = false 而将manifest fingerprint.json(Rails 4.0生成manifest.json而不是manifest.yml)推送到Heroku时未检测到,Heroku尝试再次运行预编译。然后我得到的错误是: RAILS_ENV=production bundle exec rake assets:precompile

我设定

在application.rb中。已通过运行在本地成功预编译资产

config.assets.initialize_on_precompile = false
而将manifest fingerprint.json(Rails 4.0生成manifest.json而不是manifest.yml)推送到Heroku时未检测到,Heroku尝试再次运行预编译。然后我得到的错误是:

RAILS_ENV=production bundle exec rake assets:precompile
错误可能是因为Heroku初始化了应用程序,其中包括与数据库的连接。但我不应该看到这样的信息

#lib/student_module.rb, the error pointed to this line:
user_attributes = User.new.abttributes.keys
#config/initializers/student_init.rb
require 'student_module'
ActiveRecord::Base.extend Student
因为我将config.assets.initialize_on_precompile设置为false,并在本地预编译资产


有什么建议可以解决这个问题吗?谢谢

您需要在Heroku user env compile上启用一个labs功能,该功能允许应用程序在编译时访问环境变量

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?

请访问

了解更多信息,您知道为什么这会解决问题吗?这似乎是一个违反Heroku最佳实践的快速修复方法。是的,它确实如此-这意味着构建依赖于在代码之外定义的某些东西,这些东西肯定违反了12factor。问题在于,当你的应用程序中有代码在初始化时访问数据库时,它希望数据库在那里并导致错误-这取决于gem/框架来防止这种情况发生。
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?
heroku labs:enable user-env-compile -a myapp