3. Rails のインストール

.gitignore の設定

SourceTree が楽なので、しばらくは Mac で作業する。ブランチを昨日作成した feature/configure_systems に切り替え、ここに .gitignore を作成する。昔はみな手書きで整備した .gitignore を各自が保持していたものだが、今は gibo という便利なサービスがあるので、それを使わせてもらう。Mac なら

$ brew install gibo

でインストールできる。結構頻繁にアップデートされているので、作成前に

$ gibo -u

としておくとよい。今回は

$ gibo OSX Ruby Rails vim Emacs > .gitignore

としてみた。忘れたものがあったら、後で随時追加する。

Rails のインストール

取り急ぎ Rails をインストールしてみる。ここに Gemfile を書いてみる。これで、4.1.8 以上、4.2 未満という表記になる。

source 'https://rubygems.org'
gem 'rails', '~>4.1.8'

bundle で、vendor/bundle ディレクトリに Rails をインストールする。

% bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Installing rake 10.4.2
Installing i18n 0.6.11
Using json 1.8.1
Installing minitest 5.5.0
Installing thread_safe 0.3.4
Installing tzinfo 1.2.2
Installing activesupport 4.1.8
Installing builder 3.2.2
Installing erubis 2.7.0
Installing actionview 4.1.8
Installing rack 1.5.2
Installing rack-test 0.6.2
Installing actionpack 4.1.8
Installing mime-types 2.4.3
Installing mail 2.6.3
Installing actionmailer 4.1.8
Installing activemodel 4.1.8
Installing arel 5.0.1.20140414130214
Installing activerecord 4.1.8
Using bundler 1.7.9
Installing hike 1.2.3
Installing multi_json 1.10.1
Installing thor 0.19.1
Installing railties 4.1.8
Installing tilt 1.4.1
Installing sprockets 2.12.3
Installing sprockets-rails 2.2.2
Installing rails 4.1.8
Your bundle is complete!
It was installed into ./vendor/bundle

依存関係でいろいろとインストールされる。ここで作成された Gemfile.lock が別のサーバにもインストールされることになる。このため、Gemfile と Gemfile.lock をリポジトリにコミットしておく。

Rails 環境の構築

Rails のシステムがインストールされたので、Rails の環境を構築する。Rspec を使うので tests 関係はインストールしない(-T)。また、turbolinks は今回使わないつもりなので、bundle install はスキップする(--skip-bundle)。

$ bundle exec rails new . -d postgresql -T --skip-bundle
       exist  
      create  README.rdoc
      create  Rakefile
      create  config.ru
    conflict  .gitignore
Overwrite /Users/hkob/rails/webcit3/.gitignore? (enter "h" for help) [Ynaqdh] 
       force  .gitignore
    conflict  Gemfile
Overwrite /Users/hkob/rails/webcit3/Gemfile? (enter "h" for help) [Ynaqdh] 
       force  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/secrets.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.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  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep

せっかく先に作った .gitignore を上書きしてしまったので、再度作り直しておく(自動生成したものは中にちゃんと入っているのを確認したため)。

turbolinks を無効にするために、bundle install する前に以下の作業をまとめてやっておく。最初に Gemfile の turbolinks をコメントしておく。

# gem ‘turbolinks’

次に、app/asserts/javascripts/application.js から以下の行を消しておく。

//= require turbolinks

最後に、app/views/layouts/application.html.erb の「’data-turbolinks-track’ => true」を消しておく(2行)。

  <%= stylesheet_link_tag    'application', media: 'all' %>
  <%= javascript_include_tag 'application' %>

その後 bundle install して関連する gem をインストールしておく(長くなるので Using は記録から除外しておく)。

$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Installing coffee-script-source 1.8.0
Installing execjs 2.2.2
Installing coffee-script 2.3.0
Installing coffee-rails 4.0.1
Installing jbuilder 2.2.5
Installing jquery-rails 3.1.2
Installing pg 0.17.1
Installing rdoc 4.2.0
Installing sass 3.2.19
Installing sass-rails 4.0.5
Installing sdoc 0.4.1
Installing spring 1.2.0
Installing uglifier 2.6.0
Your bundle is complete!
It was installed into ./vendor/bundle
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

以前は、別途入れていた spring が 4.1 からは標準になっていることがわかる。ここまで終わったところで、リポジトリにコミットしておく。

今日はここまで。

written by iHatenaSync