Ruby—在Heroku上部署Rails4

这里是 Heroku部署官方文档

下面是部署的步骤:

建立仓库:

$ cd my_demo_name

$ git init

$ git add .

$ git commit -m "first commit"


检查git状态

$ git status


登录heroku

$ 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

$ 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


至此,可以在浏览器打开你的网址了


补充问题:

 Rails 4的CSS 在 Heroku 上失效的解决方法

在 /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,
最后 git push 即可。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值