简体   繁体   English

Rails rake资产:用于生产的预编译

[英]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.

相关问题 生产中的 rails 6 webpacker:rake 资产:预编译失败 - rails 6 webpacker in production: rake assets:precompile fails Rails 5- RAILS_ENV =生产耙资产:预编译与耙资产:预编译之间的差异 - Rails 5- Difference between RAILS_ENV=production rake assets:precompile and rake assets:precompile rake assets:precompile 和 RAILS_ENV=production rake assets:precompile 有什么区别? - what's the differences between rake assets:precompile and RAILS_ENV=production rake assets:precompile? 耙资产:预编译生产缓慢 - rake assets:precompile is slow in production 耙式资产:预编译无法在生产环境中使用 - rake assets:precompile not working on production rake资产:预编译RAILS_ENV =生产不按要求工作 - rake assets:precompile RAILS_ENV=production not working as required 耙资产:预编译RAILS_ENV =生产错误 - rake assets:precompile RAILS_ENV=production Error rake资产:预编译:Rails中的nodigest 4 - rake assets:precompile:nodigest in Rails 4 Capistrano:KILL RAILS_ENV =生产RAILS_GROUPS =资产捆绑执行rake资产:预编译 - Capistrano: Killed RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile Rails 5生产资产预编译错误 - Rails 5 production assets precompile error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM