HerokuでRuby1.9とRails3を使って1時間でツイッターサービスを作ろう!

Redirecting...KRAY - みんなで考え、作り、価値を生み出すをやってみた。試行錯誤しながらだったので1時間以上かかったし、この通りにやって1時間でできるかどうかは知らない。

まずはRedirecting...を参考にHerokuを設定する。この記事だとローカルにRails環境を構築するのところで

rails heroku-demo

ってあるけどそれじゃ作れなくて

rails new heroku-demo

のようにnewが必要だった。それとbamboo-mri-1.9.2が使えたのでそれ選んだ。他は記事の通り。

続きはKRAY - みんなで考え、作り、価値を生み出すを見ながら。Rails3だと結構違う。
twitter-authのインストールはGemfileに

gem 'twitter-auth', :require => 'twitter_auth/engine', :git => 'git://github.com/rokudenashi/twitter-auth.git', :branch => 'rails_3'
gem 'json'

を追加して、bundle installでインストールする。
script/generateはなくなっているのでrails generateを使う。
config/routes.rbは、get "messages/index"というのが追加されているのでそれを消して

resources :messages, :only => [:index, :create]
root :to => 'messages#index'

を追加する。
app/controllers/messages_controller.rbはファイルの最初に

#-*- coding: utf-8 -*-

を追加する。あとこれはRails3関係ないけど

begin
current_user.twitter.post('/statuses/update.json', :status => "偉大なるHelloWorld")
〜〜
rescue
〜〜
end

.gemsファイルはGemfileに変わったので必要ないみたい。

こんな感じでできたのがこちら→http://rokudenashi.heroku.com/