Show page source of Rails4のインストール手順 #99983

= Rails4 のインストール手順
== インストール
=== Ruby 2.0 のインストール

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

http://rubyinstaller.org/downloads/
[[Embed(ruby2.0のインストール方法.png, caption=ruby2.0のダウンロード場所)]]

=== devKit のインストール

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

http://rubyinstaller.org/downloads/
[[Embed(DevKitのダウンロード場所.png, caption=DevKitのダウンロード場所)]]

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

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

{{{ code sh
cd C:\devkit
ruby dk.rb init
ruby dk.rb install
}}}

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

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

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

http://www.sqlite.org/download.html
[[Embed(SQLite3のダウンロード場所.png, caption=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 でファイルを展開します。
{{{ code sh
cd C:\SQLite3
C:\devkit\mingw\bin\bsdtar.exe --lzma -xf sqlite-3.7.15.2-x64-windows.tar.lzma
}}}

== 確認
=== Rails4による新規プロジェクトの作成
次に、インストールしたRails4の確認をしてみましょう。
まずは、railsコマンドにより任意の新しいプロジェクトを作成します。
{{{ code sh
rails new railsFourSample
}}}
下記のような文字列が表示され、railsFourSampleプロジェクトが作成されます。
{{{ code sh
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      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/views/layouts/application.html.erb
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      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/filter_parameter_logging.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  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
         run  bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.1.0)
Installing i18n (0.6.5)
Using minitest (4.7.5)
Installing multi_json (1.7.9)
Installing atomic (1.1.13)
Using thread_safe (0.1.2)
Using tzinfo (0.3.37)
Using activesupport (4.0.0)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.0)
Installing mime-types (1.24)
Using polyglot (0.3.3)
Installing treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.0)
Using activemodel (4.0.0)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.0)
Using activerecord (4.0.0)
Using bundler (1.3.5)
Using coffee-script-source (1.6.3)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.0.0)
Using coffee-rails (4.0.0)
Using hike (1.2.3)
Using jbuilder (1.5.0)
Using jquery-rails (3.0.4)
Using json (1.8.0)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.0.0)
Using rdoc (3.12.2)
Using sass (3.2.10)
Using sass-rails (4.0.0)
Using sdoc (0.3.20)
Using turbolinks (1.3.0)
Using uglifier (2.1.2)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
}}}

続いて、railsFourSample ディレクトリへ移動して下さい。
{{{ code sh
cd railsFourSample
}}}

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

=== Gemファイルの編集
次に、Gemfileの中身を編集して下さい。
「gem 'sqlite3'」と記載されいる箇所がありますので、先程インストールした SQLite3 のバージョン 1.3.8 を指定します。
{{{ code sh
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '1.3.8'
}}}

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

http://localhost:3000/books