• Showing Page History #99983

Rails4 のインストール手順

インストール

Ruby 2.0 のインストール

まず、Ruby 2.0 をインストールして下さい。 間もなくRuby1.8系統の保守は原則として停止しますので、この機会に2.0をインストールして下さい。 下記のURLからWindows版のRuby2.0をダウンロードして下さい。

http://rubyinstaller.org/downloads/

ruby2.0のインストール方法.png
ruby2.0のダウンロード場所

devKit のインストール

次に、DevKit をインストールして下さい。 DevKit は、下記からダウンロードできます。

http://rubyinstaller.org/downloads/

DevKitのダウンロード場所.png
DevKitのダウンロード場所

ダウンロードした「DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe」を実行し、適当な場所に展開します。 本稿では、「C:\devkit」の下に展開します。

次に、DOSプロンプトを開き、「C:\devkit」の下に移動(cd)します。 その後、下記のようにコマンドを実行します。

  1. cd C:\devkit
  2. ruby dk.rb init
  3. ruby dk.rb install

これで、DevKit のインストールが完了しました。

Rails4 のインストール

次のコマンドを順番に実行し、Rails4 をインストールします。(参考:http://www.rubylife.jp/railsinstall/rails/index4.html)

  1. gem i bundler
  2. gem i rails

SQLite3 のインストール

次に、Rails4 のアプリケーションの動作環境におけるデータベースとして、SQLite3 の実行ファイルをインストールして下さい。 SQLite3 の実行ファイルは、下記からダウンロードできます。

http://www.sqlite.org/download.html

SQLite3のダウンロード場所.png
SQLite3のダウンロード場所

ダウンロードした zip ファイルは、任意の場所に展開して下さい。

次に、Rails用のSQLite3をダウンロードします。 下記からダウンロードして下さい。(参考:https://www.ruby-forum.com/topic/4413168)

http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x64-windows.tar.lzma

C ドライブの直下に SQLite3 というディレクトリを作成し、その下に「sqlite-3.7.15.2-x64-windows.tar.lzma」を配置します。 「sqlite-3.7.15.2-x64-windows.tar.lzma」の配置後、bsdtar でファイルを展開します。

  1. cd C:\SQLite3
  2. C:\devkit\mingw\bin\bsdtar.exe --lzma -xf sqlite-3.7.15.2-x64-windows.tar.lzma

確認

Rails4による新規プロジェクトの作成

次に、インストールしたRails4の確認をしてみましょう。 まずは、railsコマンドにより任意の新しいプロジェクトを作成します。

  1. rails new railsFourSample
下記のような文字列が表示され、railsFourSampleプロジェクトが作成されます。
  1. create
  2. create README.rdoc
  3. create Rakefile
  4. create config.ru
  5. create .gitignore
  6. create Gemfile
  7. create app
  8. create app/assets/javascripts/application.js
  9. create app/assets/stylesheets/application.css
  10. create app/controllers/application_controller.rb
  11. create app/helpers/application_helper.rb
  12. create app/views/layouts/application.html.erb
  13. create app/assets/images/.keep
  14. create app/mailers/.keep
  15. create app/models/.keep
  16. create app/controllers/concerns/.keep
  17. create app/models/concerns/.keep
  18. create bin
  19. create bin/bundle
  20. create bin/rails
  21. create bin/rake
  22. create config
  23. create config/routes.rb
  24. create config/application.rb
  25. create config/environment.rb
  26. create config/environments
  27. create config/environments/development.rb
  28. create config/environments/production.rb
  29. create config/environments/test.rb
  30. create config/initializers
  31. create config/initializers/backtrace_silencers.rb
  32. create config/initializers/filter_parameter_logging.rb
  33. create config/initializers/inflections.rb
  34. create config/initializers/mime_types.rb
  35. create config/initializers/secret_token.rb
  36. create config/initializers/session_store.rb
  37. create config/initializers/wrap_parameters.rb
  38. create config/locales
  39. create config/locales/en.yml
  40. create config/boot.rb
  41. create config/database.yml
  42. create db
  43. create db/seeds.rb
  44. create lib
  45. create lib/tasks
  46. create lib/tasks/.keep
  47. create lib/assets
  48. create lib/assets/.keep
  49. create log
  50. create log/.keep
  51. create public
  52. create public/404.html
  53. create public/422.html
  54. create public/500.html
  55. create public/favicon.ico
  56. create public/robots.txt
  57. create test/fixtures
  58. create test/fixtures/.keep
  59. create test/controllers
  60. create test/controllers/.keep
  61. create test/mailers
  62. create test/mailers/.keep
  63. create test/models
  64. create test/models/.keep
  65. create test/helpers
  66. create test/helpers/.keep
  67. create test/integration
  68. create test/integration/.keep
  69. create test/test_helper.rb
  70. create tmp/cache
  71. create tmp/cache/assets
  72. create vendor/assets/javascripts
  73. create vendor/assets/javascripts/.keep
  74. create vendor/assets/stylesheets
  75. create vendor/assets/stylesheets/.keep
  76. run bundle install
  77. Fetching gem metadata from https://rubygems.org/..........
  78. Fetching gem metadata from https://rubygems.org/..
  79. Resolving dependencies...
  80. Using rake (10.1.0)
  81. Installing i18n (0.6.5)
  82. Using minitest (4.7.5)
  83. Installing multi_json (1.7.9)
  84. Installing atomic (1.1.13)
  85. Using thread_safe (0.1.2)
  86. Using tzinfo (0.3.37)
  87. Using activesupport (4.0.0)
  88. Using builder (3.1.4)
  89. Using erubis (2.7.0)
  90. Using rack (1.5.2)
  91. Using rack-test (0.6.2)
  92. Using actionpack (4.0.0)
  93. Installing mime-types (1.24)
  94. Using polyglot (0.3.3)
  95. Installing treetop (1.4.15)
  96. Using mail (2.5.4)
  97. Using actionmailer (4.0.0)
  98. Using activemodel (4.0.0)
  99. Using activerecord-deprecated_finders (1.0.3)
  100. Using arel (4.0.0)
  101. Using activerecord (4.0.0)
  102. Using bundler (1.3.5)
  103. Using coffee-script-source (1.6.3)
  104. Using execjs (1.4.0)
  105. Using coffee-script (2.2.0)
  106. Using thor (0.18.1)
  107. Using railties (4.0.0)
  108. Using coffee-rails (4.0.0)
  109. Using hike (1.2.3)
  110. Using jbuilder (1.5.0)
  111. Using jquery-rails (3.0.4)
  112. Using json (1.8.0)
  113. Using tilt (1.4.1)
  114. Using sprockets (2.10.0)
  115. Using sprockets-rails (2.0.0)
  116. Using rails (4.0.0)
  117. Using rdoc (3.12.2)
  118. Using sass (3.2.10)
  119. Using sass-rails (4.0.0)
  120. Using sdoc (0.3.20)
  121. Using turbolinks (1.3.0)
  122. Using uglifier (2.1.2)
  123. Your bundle is complete!
  124. Use `bundle show [gemname]` to see where a bundled gem is installed.

続いて、railsFourSample ディレクトリへ移動して下さい。

  1. cd railsFourSample

SQLite3 の gemのインストール

次に、SQLite3 の gem をインストールします。

  1. gem install sqlite3 --platform=ruby -- --with-opt-dir=C:\SQLite3
下記のような文字列が表示され、SQLite3のgemがインストールされます。
  1. Fetching: sqlite3-1.3.8.gem (100%)
  2. Temporarily enhancing PATH to include DevKit...
  3. Building native extensions with: '--with-opt-dir=C:\SQLite3'
  4. This could take a while...
  5. Successfully installed sqlite3-1.3.8
  6. Parsing documentation for sqlite3-1.3.8
  7. unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/sqlite3/sqlite3_native.so, skipping
  8. Installing ri documentation for sqlite3-1.3.8
  9. 1 gem installed

Gemファイルの編集

次に、Gemfileの中身を編集して下さい。 「gem 'sqlite3'」と記載されいる箇所がありますので、先程インストールした SQLite3 のバージョン 1.3.8 を指定します。

  1. # Use sqlite3 as the database for Active Record
  2. gem 'sqlite3', '1.3.8'

scaffold の実行

次に、scaffoldコマンドで任意のアプリケーションを生成してみます。

  1. rails generate scaffold book title price:integer
次に、生成したアプリケーションが使用するテーブルを生成します。
  1. rake db:migrate
次に、APサーバを起動します。
  1. rails server
最後に、下記のURLにアクセスして画面が表示されれば、成功です。

http://localhost:3000/books