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

时间:2011-10-16 21:33:08

标签: ruby-on-rails ruby-on-rails-3 heroku assets

我正在尝试为我的应用程序预编译资产以部署到Heroku,但必须遵循错误。

运行时:

RAILS_ENV=production bundle exec rake assets:precompile

错误:

/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.)

因为我在开发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

我尝试了很多,但无法使其正常工作。

我不知道这是否重要,但我的database.yml看起来像:

production:
  adapter: postgresql
  host: localhost
  database: db
  encoding: unicode
  username: user
  password: ''

1 个答案:

答案 0 :(得分:54)

老问题,但接受的答案并没有真正回答这个问题 - 我只是在搜索中找到了这个,所以我猜它是相关的。

错误的原因是gem 'pg'在生产宝石组中 运行rake assets:precompile时,将访问生产环境。因此,它正在尝试加载生产环境,但您没有安装所有依赖项

运行RAILS_ENV=production bundle exec rails server可能会给你一个类似的错误。

我可以想到两种不同的解决方案

1)查看您的应用根目录中是否有.bundle/config个文件。如果您这样做,请检查它是否显示WITHOUT :production或类似内容。删除该行或整个.bundle目录并再次运行bundle

2)在Gemfile

gem :development, :production do
  gem 'pg'
end
删除:production组时

再次运行bundle

抱歉提起旧东西......

相关问题