Ruby on Rails環境設定メモ(Windows XP)

Ruby1.9

Rubyのインストールはできたが、gemでRailsRspecを入れていたら、gemバージョンが古く、1.3.1から1.3.2にupdateしろといわれ、
gem update --system
をすると、gemが壊れた。
調べると、パッチが出ているらしいが、自分でコンパイルしてね、と書いてあるので断念。

Ruby1.8.7

Rails 2.3.4
sqlite3 1.2.3
gem 1.3.5

gem

http://www.nwlab.com/?p=58

C:\ruby\rubygems-1.3.5>ruby setup.rb
RubyGems 1.3.5 installed

・ソ=== 1.3.5 / 2009-07-21

Bug fixes:

* Fix use of prerelease gems.
* Gem.bin_path no longer escapes path with spaces. Bug #25935 and #26458.

Deprecation Notices:

* Bulk index update is no longer supported (the code currently remains, but not
the tests)
* Gem::manage_gems was removed in 1.3.3.
* Time::today was removed in 1.3.3.

                                                                                                                                                          • -

RubyGems installed the following executables:
C:/ruby/ruby-1.8.7-p72-i386-mswin32/bin/gem


C:\ruby\rubygems-1.3.5>

Rails

C:\ruby\rubygems-1.3.5>gem install rails
Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.4
Successfully installed activerecord-2.3.4
Successfully installed rack-1.0.0
Successfully installed actionpack-2.3.4
Successfully installed actionmailer-2.3.4
Successfully installed activeresource-2.3.4
Successfully installed rails-2.3.4
8 gems installed
Installing ri documentation for rake-0.8.7...
Installing ri documentation for activesupport-2.3.4...
Installing ri documentation for activerecord-2.3.4...
Installing ri documentation for rack-1.0.0...
Installing ri documentation for actionpack-2.3.4...
Installing ri documentation for actionmailer-2.3.4...
Installing ri documentation for activeresource-2.3.4...
Installing ri documentation for rails-2.3.4...
Installing RDoc documentation for rake-0.8.7...
Installing RDoc documentation for activesupport-2.3.4...
Installing RDoc documentation for activerecord-2.3.4...
Installing RDoc documentation for rack-1.0.0...
Installing RDoc documentation for actionpack-2.3.4...
Installing RDoc documentation for actionmailer-2.3.4...
Installing RDoc documentation for activeresource-2.3.4...
Installing RDoc documentation for rails-2.3.4...

C:\ruby\rubygems-1.3.5>

サンプルプロジェクト

D:\rails>rails sample
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create config/initializers
create config/locales
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create test/fixtures
create test/functional
create test/integration
create test/performance
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create Rakefile
create README
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create config/database.yml
create config/routes.rb
create config/locales/en.yml
create db/seeds.rb
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/new_rails_defaults.rb
create config/initializers/session_store.rb
create config/environment.rb
create config/boot.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/console
create script/dbconsole
create script/destroy
create script/generate
create script/runner
create script/server
create script/plugin
create script/performance/benchmarker
create script/performance/profiler
create test/test_helper.rb
create test/performance/browsing_test.rb
create public/404.html
create public/422.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log

D:\rails>cd sample

D:\rails\sample>ruby script/server
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2009-09-11 14:11:14] INFO WEBrick 1.3.1
[2009-09-11 14:11:14] INFO ruby 1.8.7 (2008-08-11) [i386-mswin32]
[2009-09-11 14:11:14] INFO WEBrick::HTTPServer#start: pid=2456 port=3000

ブラウザで http://localhost:3000

Rspec

D:\rails\sample>gem install rspec
**************************************************

Thank you for installing rspec-1.2.8

Please be sure to read History.rdoc and Upgrade.rdoc
for useful information about this release.

**************************************************
Successfully installed rspec-1.2.8
1 gem installed
Installing ri documentation for rspec-1.2.8...
Installing RDoc documentation for rspec-1.2.8...
Could not find main page README.rdoc
Could not find main page README.rdoc
Could not find main page README.rdoc
Could not find main page README.rdoc

rspec-rails

D:\rails\sample>gem install rspec-rails
**************************************************

Thank you for installing rspec-rails-1.2.7.1

If you are upgrading, do this in each of your rails apps
that you want to upgrade:

$ ruby script/generate rspec

Please be sure to read History.rdoc and Upgrade.rdoc
for useful information about this release.

**************************************************
Successfully installed rspec-rails-1.2.7.1
1 gem installed
Installing ri documentation for rspec-rails-1.2.7.1...
Installing RDoc documentation for rspec-rails-1.2.7.1...
Could not find main page README.rdoc
Could not find main page README.rdoc
Could not find main page README.rdoc
Could not find main page README.rdoc

D:\rails\sample>

scaffold

D:\rails\sample>ruby script/generate rspec_scaffold Article title:string story:string
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/articles
exists app/views/layouts/
exists public/stylesheets/
create spec/controllers/
create spec/routing/
create spec/models/
create spec/helpers/
create spec/fixtures/
create spec/views/articles
create spec/integration/
create app/views/layouts/articles.html.erb
create public/stylesheets/scaffold.css
create spec/routing/articles_routing_spec.rb
create spec/controllers/articles_controller_spec.rb
create app/controllers/articles_controller.rb
create spec/helpers/articles_helper_spec.rb
create app/helpers/articles_helper.rb
create app/views/articles/index.html.erb
create app/views/articles/show.html.erb
create app/views/articles/new.html.erb
create app/views/articles/edit.html.erb
create app/models/article.rb
create spec/fixtures/articles.yml
create spec/models/article_spec.rb
create spec/views/articles/edit.html.erb_spec.rb
create spec/views/articles/index.html.erb_spec.rb
create spec/views/articles/new.html.erb_spec.rb
create spec/views/articles/show.html.erb_spec.rb
create spec/integration/articles_spec.rb
create db/migrate
create db/migrate/20090911051712_create_articles.rb
route map.resources :articles

sqlite3

ダウンロードして、パスを通しておく

D:\rails\sample>gem install sqlite3-ruby --version=1.2.3
Successfully installed sqlite3-ruby-1.2.3-x86-mswin32
1 gem installed
Installing ri documentation for sqlite3-ruby-1.2.3-x86-mswin32...
Installing RDoc documentation for sqlite3-ruby-1.2.3-x86-mswin32...

D:\rails\sample>

migrate

D:\rails\sample>rake db:migrate
(in D:/rails/sample)
== CreateArticles: migrating =================================================

    • create_table(:articles)

-> 0.0000s
== CreateArticles: migrated (0.0000s) ========================================


D:\rails\sample>

動かす

D:\rails\sample>ruby script/server
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2009-09-11 14:32:00] INFO WEBrick 1.3.1
[2009-09-11 14:32:00] INFO ruby 1.8.7 (2008-08-11) [i386-mswin32]
[2009-09-11 14:32:00] INFO WEBrick::HTTPServer#start: pid=3952 port=3000

http://localhost:3000/articles

Rspecでテスト

D:\rails\sample>ruby script/generate rspec
exists lib/tasks
create lib/tasks/rspec.rake
create script/autospec
create script/spec
create script/spec_server
exists spec
create spec/rcov.opts
create spec/spec.opts
create spec/spec_helper.rb

D:\rails\sample>
D:\rails\sample>rake db:migrate RAILS_ENV=test
(in D:/rails/sample)
== CreateArticles: migrating =================================================

    • create_table(:articles)

-> 0.0150s
== CreateArticles: migrated (0.0150s) ========================================


D:\rails\sample>ruby script/spec spec
....................................

Finished in 3.485 seconds

36 examples, 0 failures

D:\rails\sample>

gem list

D:\rails\sample>gem list

LOCAL GEMS ***

actionmailer (2.3.4)
actionpack (2.3.4)
activerecord (2.3.4)
activeresource (2.3.4)
activesupport (2.3.4)
rack (1.0.0)
rails (2.3.4)
rake (0.8.7)
rspec (1.2.8)
rspec-rails (1.2.7.1)
sqlite3-ruby (1.2.3)