Ubuntu上使用Heroku 雲端服務發布有資料庫的Rails應用

來源:互聯網
上載者:User
程式最初是使用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



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.