herokuというrailsアプリケーションのホスティングサービスを使ってみました。以前はブラウザでrailsアプリが開発できる、ということでしたが、今はheroku gardenという名前になっています。ブラウザを使った開発も面白そうですが、まずはheroku.comを使ってみます。
heroku.comを使用する場合は、自分の環境でrailsアプリを作成したものをgit pushすると、herokuにdeployされます。料金はストレージと通信料、そして各種オプションで決まるようです。ストレージ5Mで通信がほとんど無ければfreeなので、その範囲内で試してみます。
まずはherokuをインストール。
gitのremoteリポジトリを使用する為に、公開鍵をアップします。
railsアプリを作成し、git commitまでします。
1
2
3
|
$ rails foobar
$ cd foobar
$ git init && git add . && git commit -m "first commit" |
heroku側にアプリケーションのdeploy先を作成します。
createの後にアプリケーション名を入れないと、変な名前(今回はhollow-ice-37でした)を付けられてしまいます。ちょっと嫌なのでやり直し。
1
2
3
|
$ heroku destroy hollow-ice-37
$ heroku create foobar(実際はアプリの名前)
$ git push heroku master |
git pushすると、自動的にdeployされます。deployされたアプリケーションをブラウザで確認したところ、
|
Missing the Rails 2.1.1 gem. Please `gem install -v=2.1.1 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed. |
と。config/environment.rbの「RAILS_GEM_VERSION」をコメントアウトし、再度git pushしたところ、railsのデフォルトの画面が表示されました。
これだけだとよく分からないので、ローカルでscaffoldして、herokuにアップしてみます。
1
2
3
|
$ script/generate scaffold task name:string start:datetime end:datetime owner:integer
$ rake db:migrate
$ script/server |
普通に動くことを確認し、git push。ただ、これだけだとdeploy先でdb:migrateが実行されないらしく、ブラウザで確認するとエラーが出てました。
deployされたアプリケーションのログを見る為には、heroku logsを実行します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
$ heroku logs
==> log/production.log <==
# Logfile created on Thu Jun 18 11:14:08 -0700 2009
Processing TasksController#index (for 59.156.119.10 at 2009-06-18 11:14:17) [GET]
ActiveRecord::StatementInvalid (PGError: ERROR: relation "tasks" does not exist
: SELECT * FROM "tasks" ):
app/controllers/tasks_controller.rb:5:in `index'
/home/heroku_rack/lib/static_assets.rb:9:in `call'
/home/heroku_rack/lib/last_access.rb:15:in `call'
thin (1.0.1) lib/thin/connection.rb:80:in `pre_process'
thin (1.0.1) lib/thin/connection.rb:78:in `catch'
thin (1.0.1) lib/thin/connection.rb:78:in `pre_process'
thin (1.0.1) lib/thin/connection.rb:57:in `process'
thin (1.0.1) lib/thin/connection.rb:42:in `receive_data'
eventmachine (0.12.6) lib/eventmachine.rb:240:in `run_machine'
eventmachine (0.12.6) lib/eventmachine.rb:240:in `run'
thin (1.0.1) lib/thin/backends/base.rb:57:in `start'
thin (1.0.1) lib/thin/server.rb:150:in `start'
thin (1.0.1) lib/thin/controllers/controller.rb:80:in `start'
thin (1.0.1) lib/thin/runner.rb:173:in `send'
thin (1.0.1) lib/thin/runner.rb:173:in `run_command'
thin (1.0.1) lib/thin/runner.rb:139:in `run!'
thin (1.0.1) bin/thin:6
/usr/local/bin/thin:19:in `load'
/usr/local/bin/thin:19 |
PGError…。どうやらPostgreSQLを使っているようです。
deploy先でrakeを実行したい場合はheroku rakeコマンドを使います。
これでscaffoldした内容を確認できました。
Sorry, comments are closed for this article.