Ruby-on-rails Rails rake 资产:为生产预编译
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7787476/
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
Rails rake assets:precompile for production
提问by Kieran Klaassen
I'm trying to precompile the assets for my app to deploy to Heroku but have to following error.
我正在尝试为我的应用程序预编译资产以部署到 Heroku,但必须遵循错误。
When running:
运行时:
RAILS_ENV=production bundle exec rake assets:precompile
Error:
错误:
/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
Because I use in development SQLite and in production Postgresql the following Gemfile
因为我在开发 SQLite 和生产 Postgresql 中使用以下 Gemfile
gem "rails", "~> 3.1.0"
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
gem 'sass-rails', "~> 3.1.0"
group :assets do
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
gem 'compass', '~> 0.12.alpha.0'
gem 'html5-boilerplate'
end
I tried a lot but can't get this working.
我尝试了很多,但无法正常工作。
I don't know if this is important but my database.yml looks like:
我不知道这是否重要,但我的 database.yml 看起来像:
production:
adapter: postgresql
host: localhost
database: db
encoding: unicode
username: user
password: ''
回答by mraaroncruz
Old question but the accepted answer doesn't really answer the question - and I just found this in a search so I guess it's relevant.
老问题,但接受的答案并没有真正回答这个问题——我只是在搜索中找到了这个,所以我想它是相关的。
The reason for the error is that gem 'pg'is in the production gem group.
When you run rake assets:precompilethe production environment is accessed. So it is trying to load the production environment but you don't have all of the dependencies installed.
错误的原因gem 'pg'是在生产 gem 组中。
当你运行rake assets:precompile生产环境时被访问。所以它正在尝试加载生产环境,但您没有安装所有依赖项。
Running RAILS_ENV=production bundle exec rails serverwould probably give you a similar error.
运行RAILS_ENV=production bundle exec rails server可能会给你一个类似的错误。
I can think of two different solutions
我可以想到两种不同的解决方案
1) Look to see if you have a .bundle/configfile in your app's root. If you do, check if it says WITHOUT :productionor similar. Either remove that line or the whole .bundledirectory and run bundleagain.
1) 查看.bundle/config您的应用程序根目录中是否有文件。如果你这样做,检查它是否说WITHOUT :production或类似。删除该行或整个.bundle目录并bundle再次运行。
2) in Gemfile
2) 在 Gemfile
gem :development, :production do
gem 'pg'
end
while removing the :productiongroup
run bundleagain
同时删除:production组再次
运行bundle
Sorry to bring up old stuff...
对不起,提出旧的东西......

