歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu上使用Heroku 雲服務發布有數據庫的Rails應用

Ubuntu上使用Heroku 雲服務發布有數據庫的Rails應用

日期:2017/2/28 15:59:58   编辑:Linux教程

程序最初是使用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

Copyright © Linux教程網 All Rights Reserved