[英]Rails rake assets:precompile for production
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: ''
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. 错误的原因是
gem 'pg'
在生产宝石组中。
When you run rake assets:precompile
the production environment is accessed. 运行
rake assets:precompile
访问生产环境。 So it is trying to load the production environment but you don't have all of the dependencies installed . 因此它正在尝试加载生产环境, 但您没有安装所有依赖项 。
Running RAILS_ENV=production bundle exec rails server
would 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/config
file in your app's root. 1)查看您的应用程序根目录中是否有
.bundle/config
文件。 If you do, check if it says WITHOUT :production
or similar. 如果您这样做,请检查它是否显示为
WITHOUT :production
或类似。 Either remove that line or the whole .bundle
directory and run bundle
again. 删除该行或整个
.bundle
目录并再次运行bundle
。
2) in Gemfile
2)在
Gemfile
gem :development, :production do
gem 'pg'
end
while removing the :production
group 同时删除
:production
组
run bundle
again 再次运行
bundle
Sorry to bring up old stuff... 抱歉带来旧东西......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.