2011-10-16 147 views
25

我试图预编译我的应用程序的资产以部署到Heroku,但必须遵循以下错误。Rails Rake资产:用于生产的预编译

当运行:

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

你尝试过这个在雪松堆栈? 'heroku创建 - 堆雪松' – daniel

回答

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再次

抱歉给旧的东西...

+4

对不起,我不小心downvoted你,但现在我不能撤消它:(:(我真的找到你的答案有用 –

+0

@SherwinYu只需再次点击downvote图标,你的downvote将被取消。 –

+0

@DavidTuite不幸的是,如果你已经有一段时间了 - 你的downvote会被锁定,除非回答被编辑 –