这里是 Heroku部署官方文档:
下面是部署的步骤:
$ cd my_demo_name
$ git init
$ git add .
$ git commit -m "first commit"
$ git status
$ heroku login
// 输入 $ email: $ password:
$ heroku create my_demo_name
// 生成网址 http://my_demo_name.herokuapp.com
$ git push heroku master
Permission denied (publickey).
fatal: Could not read from remote repository.
// 生成 ssh
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mac/.ssh/id_rsa): /Users/mac/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mac/.ssh/id_rsa.
Your public key has been saved in /Users/mac/.ssh/id_rsa.pub.
$ heroku keys:add
Found the following SSH public keys:
1) github_rsa.pub
2) id_rsa.pub
Which would you like to use with your Heroku account? id_rsa.pub
! Invalid choice
tindle:bootstrap-todo-app-master mac$ heroku keys:add
Found the following SSH public keys:
1) github_rsa.pub
2) id_rsa.pub
Which would you like to use with your Heroku account? 2
Uploading SSH public key /Users/mac/.ssh/id_rsa.pub... done
Heroku 数据库只支持 PostgreSQL, 所以要修改 Gemfile:
# gem 'sqlite3'
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
// 修改完要安装更新
$ bundle
// 更新完成后可以用 git status
// 查看,Gemfile , Gemfile.lock都已修改
$ git add .
$ git commit -m "edit msg"
$ git push heroku master
// 最后,数据库迁移
$ heroku run rake db:create
$ heroku run rake db:migrate
至此,可以在浏览器打开你的网址了
在 /config/environments/production.rb 中设置:
config.cache_classes = true config.serve_static_assets = true config.assets.compile = true config.assets.digest = true
保证 /config/database.yml 中有:
production: adapter: postgresql encoding: unicode database: Your_appname_production
然后再 git add, git commit,