rails newでつまづく<解決編>

昨日(2012/1/16)の記事で,rails newしても新規のRailsアプリケーションがきちんと生成されない,ということでエントリを書きましたが,今日になってその記事にコメントがあり,RubyInstaller Development Kit(以下,DevKitとする)を入れると解決できるかもしれない,という内容のコメントが寄せられておりましたので試して見ることに.
コメントを寄せて頂いたsmilerubyさんありがとうございますm(_ _)m

0.おことわり

OSにWindows XP Professional Service Pack 3,Rubyのバージョンは1.9.3-p0,Railsのバージョンは3.1.3がインストールされている環境で行なっています.

1. DevKitのexeファイルのダウンロード

まずこのサイトにアクセスします.

上記の画像の赤枠で囲っている部分からDevKitのexeファイルをダウンロードします.なお2012年1月17日現在,DevKitのexeファイル名は

  • DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

となっています.

2. exeファイルの展開

ダウンロードしたexeファイルを展開します.この時展開する先は任意で良いのですが展開時に結構多くのファイルやフォルダが展開されてしまうので,例えば

C:\DevKit

などというように展開先のフォルダを作った上で展開することをおすすめいたします.以後はC:\DevKitに解凍したものとして話を進めていきます.

3. DevKitのインストール

展開が終わったらDevKitをインストールしていきます.インストールはDevelopment Kit - GitHubを参考にして行いました.
コマンドプロンプトを開いて,DevKitをインストールしているフォルダ(ディレクトリ)まで移動します.なおコマンドプロンプトについては私がインストールを行った際はパーミッションエラー等を予見したので念のため

スタートメニュー→すべてのプログラム→Ruby 1.9.3-p0→Start Command Prompt with Ruby

というように辿ってAdministrator権限で実行した上で行いました.
移動が済んだら次のコマンド

C:\DevKit>ruby dk.rb init

を入力して下さい.この後

[INFO] found RubyInstaller v1.9.3 at C:/Ruby

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.

というメッセージが表示されればOKです.このコマンドではconfig.ymlというファイルが生成されます.
次にそのconfig.ymlを適当なテキストエディタで開いてみます.ファイルの中身は例えば次のような感じになっているはずです.

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#

これはRubyがインストールされているフォルダがどこかを記しています.Rubyがインストールされているフォルダを適切に示せているのであれば何もいじらずにファイルを閉じます.
config.ymlの中身が適切であることを確かめたら,

C:\DevKit>ruby dk.rb install

コマンドプロンプトに打ち込むとDevKitのインストールが行われ,インストール自体は一瞬で完了します.

4. 改めてrails newを試してみる

DevKitのインストールが終わったので,改めてrails newが出来るか試して見ることに.今回はHTTP_PROXY設定済み,Administrator権限でコマンドプロンプトを開いているという前提で行いました.

C:\Rails>rails new app2

などと打ち込んでいきます.

create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/images/rails.png
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create app/mailers/.gitkeep
create app/models/.gitkeep
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/initializers/wrap_parameters.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create lib/assets
create lib/assets/.gitkeep
create log
create log/.gitkeep
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create script
create script/rails
create test/fixtures
create test/fixtures/.gitkeep
create test/functional
create test/functional/.gitkeep
create test/integration
create test/integration/.gitkeep
create test/unit
create test/unit/.gitkeep
create test/performance/browsing_test.rb
create test/test_helper.rb
create tmp/cache
create tmp/cache/assets
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.gitkeep
create vendor/plugins
create vendor/plugins/.gitkeep
run bundle install

とここまでは特に問題なく進行し,run bundle installで一時停止した後,

which: no sudo in (C:\Ruby\bin;C:\Ruby\bin;C:\sqlite;C:\Perl\site\bin;C:\Perl\bi
n;C:\Program Files\ThinkPad\Utilities;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\
System32\Wbem;C:\Program Files\Diskeeper Corporation\Diskeeper\;C:\Program Files
\ThinkPad\ConnectUtilities;%QUARTUS_ROOTDIR%\bin;C:\Program Files\Toshiba\Blueto
oth Toshiba Stack\sys\;C:\Program Files\Common Files\Lenovo;C:\Program Files\Int
el\WiFi\bin\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\w32tex\bin;C:\gs\gs9.
02\bin;C:\gs\gs9.02\lib;C:\Program Files\QuickTime\QTSystem\;C:\Strawberry\perl\
bin;C:\Strawberry\perl\site\bin;C:\Strawberry\c\bin;C:\Program Files\MySQL\MySQL
Server 5.5\bin;C:\Program Files\Gow\bin;C:\Program Files\Java\jdk1.7.0\bin;)

またあの忌々しいメッセージが… 昨日と同じ展開になるのかと不安になったのですが,

Fetching source index for http://rubygems.org/
Using rake (0.9.2.2)
Using multi_json (1.0.4)
Using activesupport (3.1.3)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.3)
Using erubis (2.7.0)
Using rack (1.3.6)
Using rack-cache (1.1)
Using rack-mount (0.8.3)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.0.3)
Using actionpack (3.1.3)
Using mime-types (1.17.2)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.3.0)
Using actionmailer (3.1.3)
Using arel (2.2.1)
Using tzinfo (0.3.31)
Using activerecord (3.1.3)
Using activeresource (3.1.3)
Using ansi (1.4.1)
Using bundler (1.0.21)
Using coffee-script-source (1.2.0)
Using execjs (1.2.13)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.6.5)
Using rdoc (3.12)
Using thor (0.14.6)
Using railties (3.1.3)
Using coffee-rails (3.1.1)
Using jquery-rails (1.0.19)
Using rails (3.1.3)
Using sass (3.1.12)
Using sass-rails (3.1.5)
Using sqlite3 (1.3.5)
Using turn (0.8.3)
Using uglifier (1.2.2)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem
is installed.

というようにメッセージが表示され,無事rails newによる新規アプリケーション生成を行うことが出来たようです.
そこで今日はさらに一歩踏み込んで,rails serverが実行できるか試して見ることにしました.

5. rails serverで起動できるか

今度は新規で生成したアプリケーションのフォルダに移動し,

C:\Rails\app1>rails server

と打ち込んでみます.打ち込んでからメッセージが表示されるまでしばらく経つと

=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server

というメッセージが表示されますが,これはまだ途中です.この後更に

[2012-01-17 23:14:42] INFO WEBrick 1.3.1
[2012-01-17 23:14:42] INFO ruby 1.9.3 (2011-10-30) [i386-mingw32]
[2012-01-17 23:14:42] INFO WEBrick::HTTPServer#start: pid=2484 port=3000

という表示がなされるはずです.もし途中で

というようなポップアップが出てきたらブロックを解除して下さい.
この後,自分が使っているブラウザで

http://localhost:3000/

を入力してアクセスできるか試してみます.

というようなウィンドウが表示されたら成功です.なおコマンドプロンプトを閉じてブラウザを更新すると上記の画像のページは表示されなくなるのでこのことによってrails serverが正常に行えているかどうかを確認することが出来ます.
ということで,rails newによる新規アプリケーション生成を行うことが出来たので,今日はこの辺で.