遅ればせながら、1時間で作れる偉大なるHelloWorldサービスを作ってみました。

環境はRails 3.0.9。

こちらを参照して。

さくっとrails作ってTwitterにアプリ登録し、twitter-authのプラグイン入れて、

jacoyutorius$ rails generate twitter_auth

セイ!

jacoyutorius$ rails generate twitter_auth
jacoyutorius$

・・・・?

jacoyutorius$ rails generate twitter_auth

セイ!

jacoyutorius$ rails generate twitter_auth
jacoyutorius$

へんじがない、ただのしかばねのようだ。

このプラグインがいかんのだろうか。

ふつうにgenerateしてみる。

jacoyutorius$ rails g human name:string age:integer

セイ!

jacoyutorius$ rails g human name:string age:integer
jacoyutorius$

へんじがない、ただの(ry

ログを確認してみる。

〜/twitter_helloworld/log/development.log

DEPRECATION WARNING: Use toplevel init.rb; rails/init.rb is deprecated: /Users/jacoyutorius/github/rails/twitter_helloworld/vendor/plugins/twitter-auth/rails/init.rb. (called from  at /Users/jacoyutorius/github/rails/twitter_helloworld/config/environment.rb:5)
DEPRECATION WARNING: config.gem is deprecated, and you tried to activate the 'oauth' gem ({}) using it.
Please add 'oauth' to your Gemfile. (called from block in  at /Users/jacoyutorius/github/rails/twitter_helloworld/vendor/plugins/twitter-auth/rails/init.rb:2)
DEPRECATION WARNING: Use toplevel init.rb; rails/init.rb is deprecated: /Users/jacoyutorius/github/rails/twitter_helloworld/vendor/plugins/twitter-auth/rails/init.rb. (called from  at /Users/jacoyutorius/github/rails/twitter_helloworld/config/environment.rb:5)
DEPRECATION WARNING: config.gem is deprecated, and you tried to activate the 'oauth' gem ({}) using it.
Please add 'oauth' to your Gemfile. (called from block in  at /Users/jacoyutorius/github/rails/twitter_helloworld/vendor/plugins/twitter-auth/rails/init.rb:2)
DEPRECATION WARNING: Use toplevel init.rb; rails/init.rb is deprecated: /Users/jacoyutorius/github/rails/twitter_helloworld/vendor/plugins/twitter-auth/rails/init.rb. (called from  at /Users/jacoyutorius/github/rails/twitter_helloworld/config/environment.rb:5)
DEPRECATION WARNING: config.gem is deprecated, and you tried to activate the 'oauth' gem ({}) using it.
Please add 'oauth' to your Gemfile. (called from block in  at /Users/jacoyutorius/github/rails/twitter_helloworld/vendor/plugins/twitter-auth/rails/init.rb:2)

ぎゃああああ大量のワーニングが!!

まるでパトレイバー劇場版一作目で、遊馬がHOSをハッキングした際に現れたメッセージみたい。

ハッカーっぽいね♪

なんて言ってる場合じゃない。こちとら1時間でできるTwitterアプリを作ってる途中なのだ。

こんなところでこけてたまるか(既にこけてるが)

落ち着いて読んでみると、どうも”oauth”がGemに無いってことか。

そういえば、こちら にもしっかりと書いてあったね。Rails3でやるときはGemに追加しろと。

jacoyutorius$ bundle install
Fetching git://github.com/rokudenashi/twitter-auth.git
remote: Counting objects: 1140, done.
remote: Compressing objects: 100% (477/477), done.
remote: Total 1140 (delta 541), reused 1088 (delta 521)
Receiving objects: 100% (1140/1140), 613.46 KiB | 211 KiB/s, done.
Resolving deltas: 100% (541/541), done.
Fetching source index for http://rubygems.org/
Using rake (0.9.2)
Using abstract (1.0.0)
Using activesupport (3.0.9)

~(省略)~

ということで、Gemfileを修正して、bundle install。

jacoyutorius$ rails g twitter_auth
      create  db/migrate/001_twitter_auth_migration.rb
      create  app/models/user.rb
      create  config/twitter_auth.yml
jacoyutorius$ rake db:migrate
==  TwitterAuthMigration: migrating ===========================================
-- create_table(:users)
   -> 0.0039s
==  TwitterAuthMigration: migrated (0.0040s) ==================================
jacoyutorius$ heroku stack
  aspen-mri-1.8.6
* bamboo-mri-1.9.2
  bamboo-ree-1.8.7
  cedar (beta)

念のためheroku側のバージョンを確認。問題ないね。

jacoyutorius$ git add .
jacoyutorius$ git commit -m "The Great HelloWorld"
[master (root-commit) a910b1d] The Great HelloWorld
 89 files changed, 12542 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 Gemfile
 create mode 100644 Gemfile.lock
 create mode 100644 README
 create mode 100644 Rakefile

~(省略)~

jacoyutorius$ git push heroku master
Identity added: /Users/jacoyutorius/.ssh/id_rsa (/Users/jacoyutorius/.ssh/id_rsa)
Counting objects: 141, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (116/116), done.
Writing objects: 100% (141/141), 114.57 KiB, done.
Total 141 (delta 7), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Detected Rails is not set to serve static_assets
       Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
       Installing rails3_disable_x_sendfile... do

~(省略)~

jacoyutorius$ heroku rake db:migrate
** TwitterAuth initialized properly.
Migrating to TwitterAuthMigration (1)
==  TwitterAuthMigration: migrating ===========================================
-- create_table(:users)
   -> 0.0124s
==  TwitterAuthMigration: migrated (0.0126s) ==================================

問題なくpushできた。

その後綴りミスが2カ所くらいあってエラーになったけど、問題なく修正。

偉大なるHelloWorld

こんな感じで。

ということで、人のブログはしっかり読みましょうね。