程式最初是使用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雲端服務器上面測試我的資料庫應用了
http://BerryreloadDemoApp.heroku.com/users
參考:
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