Ubuntu上使用Heroku 云服务发布有数据库的Rails应用


程序最初是使用sqlite3数据库的。

修改Gemfile文件,针对heroku部署加入pg的支持
group :production do
  # gems specifically for Heroku go here
  gem "pg"
end

bundle install

预编译一些文件,否则在heroku上面会出错

bundle exec rake assets:precompile

发布应用到给Github上面

$ git add .
$ git commit -a -m "Done with the demo app"
              Done with the demo app, add heroku pg database support
 $ git push

发布应用到heroku服务器上面
$ heroku create
$ git push heroku master
$ heroku rake db:migrate

$ heroku rename BerryreloadDemoApp

现在可以在heroku云服务器上面测试我的数据库应用了

参考:

Ubuntu上使用Heroku 云服务发布Rails应用

如果执行命令

$ bundle exec rake assets:precompile

报错如下:
rake aborted!
undefined method `prerequisites' for nil:NilClass
(See full trace by running task with --trace)

再次执行命令

$ bundle exec rake assets:precompile --trace

报错如下:

rake aborted!
undefined method `prerequisites' for nil:NilClass
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/rspec-rails-2.0.1/lib/rspec/rails/tasks/rspec.rake:3:in `<top (required)>'

结论是rspec-rails-2.0.1和rake, Rails 3.1.3不兼容,需要升级

升级办法:

修改项目的Gemfile,去掉rspec-rails的版本号,如果你是根据教材Ruby on Rails 3 Tutorial设置了rspec-rails的版本号的话。

group :development do
  gem 'rspec-rails'
end

group :test do
  gem 'rspec'
  gem 'webrat'
end


最后执行命令

$ bundle update rspec-rails

结果显示升级到了rspec-rails 2.8.1

再次执行命令成功。

$ bundle exec rake assets:precompile

然后,

$ git add .

$ git commit -am "Done with static pages and precompile for heroku"

$ git push

$ git push heroku

$ heroku rake db:migrate

相关内容