【问题标题】:Rails rake assets:precompile for productionRails rake assets:precompile for production
【发布时间】:2011-12-08 21:42:15
【问题描述】:

我正在尝试为我的应用预编译资产以部署到 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: ''

【问题讨论】:

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


【解决方案1】:

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

错误原因是gem 'pg'在生产gem组中。
当您运行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

很抱歉提出旧的东西...

【讨论】:

  • 对不起,我不小心给你投了反对票,但现在我无法撤消它:( -- 我实际上发现你的回答很有用
  • @SherwinYu 只需再次单击反对票图标,您的反对票将被取消。
  • @DavidTuite 不幸的是,如果已经有一段时间了,你不能 - 你的反对票会被锁定,除非答案被编辑。
  • 我只是在某处读到,如果我编辑它可以重新投票@SherwinYu 让我们测试一下!谢谢克里斯托夫哈里斯顺便说一句
  • @pferdefleisch 感谢您的回答。解决方案 2) 非常适合我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-04
  • 1970-01-01
  • 2014-05-11
  • 1970-01-01
  • 2019-10-12
  • 2015-08-05
  • 1970-01-01
相关资源
最近更新 更多