2012年11月16日(Fri)
Windows 7上で作ったRuby on RailsのWebアプリをHerokuで動かす
前提
- Windows 7
- gitインストール済み
- sshインストール済み
- www.heroku.comのアカウント登録済み
- heroku-toolbelt.exeのインストール済み
- gem install bundler 済み
問題
- Windows 7上で作ったRuby on RailsのWebアプリをHerokuで動かしたい
解決
- 1. Ruby on RailsをWindows 7上にインストールする。
- 2. Webアプリをローカルに用意する。
- 3. WebアプリをHerokuに配置して動かす。
詳細
1. Ruby on RailsをWindows 7上にインストールする。
- https://devcenter.heroku.com/articles/rails3 を読む。
- Rubyのバージョンを確認する。
c:\work> ruby -v ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
- Herokuにログインする。
c:\work> heroku login Enter your Heroku credentials. Email: (メールアドレス) Password (typing will be hidden): (パスワード) Authentication successful.
- Railsをインストール
c:\work> gem install rails
.
.
.
Fetching: json-1.7.5.gem (100%)
ERROR: Error installing rails:
The 'json' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
- DevKit がいるらしい。
- http://rubyinstaller.org/downloads から DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe 入手。
- https://github.com/oneclick/rubyinstaller/wiki/Development-Kit を読む。
c:\work> DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe (展開場所は c:\devkit にした) c:\work> cd \devkit c:\devkit> ruby dk.rb init [INFO] found RubyInstaller v1.9.2 at C:/Program Files (x86)/ruby-1.9.2 Initialization complete! Please review and modify the auto-generated 'config.yml' file to ensure it contains the root directories to all of the installed Rubies you want enhanced by the DevKit.
- あれ? 私は C:\ruby-1.9.2 にある rubyを使っていたはずだが。
c:\devkit> which ruby
ruby:
C:\ruby-1.9.2\bin\ruby.EXE
- ですよね。 ということで config.ymlを編集して、C:\ruby-1.9.2 に変更。
C:\devkit> vi config.yml (C:/Program Files (x86)/ruby-1.9.2をC:\ruby-1.9.2に変更) C:\devkit> ruby dk.rb review Based upon the settings in the 'config.yml' file generated from running 'ruby dk.rb init' and any of your customizations, DevKit functionality will be injected into the following Rubies when you run 'ruby dk.rb install'. C:/ruby-1.9.2 C:\devkit> ruby dk.rb install [INFO] Updating convenience notice gem override for 'C:/ruby-1.9.2' [INFO] Installing 'C:/ruby-1.9.2/lib/ruby/site_ruby/devkit.rb'
- DevKitがちゃんと入ったのを確認。
C:\devkit> gem install rdiscount --platform=ruby Fetching: rdiscount-1.6.8.gem (100%) Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... Successfully installed rdiscount-1.6.8 1 gem installed Installing ri documentation for rdiscount-1.6.8... Installing RDoc documentation for rdiscount-1.6.8...
- 再度Railsをインストール。
c:\devkit> cd \work c:\work> gem install rails Successfully installed json-1.7.5 ←さっきはこけたけど、今度は入ったよ。 ... Successfully installed rails-3.2.9 ... c:\work> rails -v Rails 3.2.9
2. Webアプリをローカルに用意する。
c:\work> rails new myapp c:\work> cd myapp c:\work\myapp> vi Gemfile (gem 'sqlite3' の行を gem 'pg' に書き換える) c:\work\myapp> bundle install
- ローカルでテストする。
c:\work\myapp> rails server (ブラウザで http://localhost:3000 にアクセス。Welcome aboardのページが表示)
3. WebアプリをHerokuに配置して動かす。
c:\work\myapp> git init c:\work\myapp> git add . c:\work\myapp> git commit -m "init" c:\work\myapp> heroku create (ここでHeroku上のアプリのURLが表示される) Git remote heroku added c:\work\myapp> git push heroku master
- これで、Heroku上のアプリのURLにアクセスすると、Welcome aboardの画面が出る。
トラックバック - http://d.hatena.ne.jp/hyuki/20121116/heroku
リンク元
- 70 https://www.google.co.jp/
- 26 http://t.co/sj8Tp8u6
- 20 http://reader.livedoor.com/reader/
- 17 http://t.co/yj0CavHB
- 15 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=9&ved=0CHAQFjAI&url=http://d.hatena.ne.jp/hyuki/20121116/heroku&ei=GE28ULaVIMyNmQXltYHwCw&usg=AFQjCNHZ_j9zuiiKq1-crSngwg3xzltw7w&sig2=RLxthSUjJcVsOTWkOLxyDw
- 13 http://b.hatena.ne.jp/entrylist/it
- 12 http://www.hyuki.com/
- 11 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0CE4QFjAD&url=http://d.hatena.ne.jp/hyuki/20121116/heroku&ei=HimzUKuTL4nqmAXUtoGQAw&usg=AFQjCNHZ_j9zuiiKq1-crSngwg3xzltw7w&sig2=tWBFs2gvMhzK22dp4uPFxA
- 9 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCgQFjAA&url=http://d.hatena.ne.jp/hyuki/&ei=m_elUNalJOLRmAWlgYHgBw&usg=AFQjCNGONjcLeAXIk0m_IEfon-cvppAUdQ
- 7 http://www.google.co.jp/url?sa=t&rct=j&q=ruby+on+rails+windows&source=web&cd=4&ved=0CEQQFjAD&url=http://d.hatena.ne.jp/hyuki/20121116/heroku&ei=1GL2UPjsO8G2kAXb9ICQDQ&usg=AFQjCNHZ_j9zuiiKq1-crSngwg3xzltw7w





