LoginSignup
62
62

More than 5 years have passed since last update.

最近試しているRailsのプロジェクト構築の手順

Last updated at Posted at 2014-10-06

基本の手順

homebrewやrbenvは何かでインストールしている前提。

rbenvで新しいrubyのバージョンを入れたばかりの仮定。グローバルを汚さずに、なるべくプロジェクト内にgemを保持するポリシーで進める。

$ rbenv exec gem install bundler # bundlerのみインストール

# 以下新規プロジェクト作成
$ cd path/to/project # railsを作成したいプロジェクトのパスへ移動。無ければ作ること。
$ echo 2.1.3 > .ruby-version # rbenvのrubyバージョン指定
$ cat .ruby-version # 例えば下記のようになる
2.1.3
$ bundle init # Gemfileのひな形作成
$ vi Gemfile # railsの設定だけコメントされているはずなので欲しいバージョンに設定
$ cat Gemfile # 例えば下記のようになる
# A sample Gemfile
source "https://rubygems.org"

gem "rails", "~>4.0.2"
$ bundle install --path vendor/bundle # 自プロジェクト内指定でインストール
$ bundle exec rails new . -T # テストなしでインストール
      exist  
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
    conflict  Gemfile
Overwrite /path/to/project/Gemfile? (enter "h" for help) [Ynaqdh] # Yで上書き
$ bundle exec rails s # サーバー起動

もしもBundler could not find compatible versions for gem "sprockets"が出たらGemfile.lockを削除し、改めてbundle installすると良さそう。
参考:http://qiita.com/fireowl11/items/7fa0a084857121398d44

もしもグローバルなruby環境にgemをインストールしてしまったら下記で綺麗さっぱりらしい。

$ rbenv exec gem list | awk '{print "rbenv exec gem uninstall " $1}' | sh -xv

参考:http://qiita.com/emadurandal/items/a60886152a4c99ce1017

RSpecの準備

Gemfileに下記を記述して

group :test do
  gem "rspec"
  gem "rspec-rails"
end
$ bundle install
$ bundle exec rails g rspec:install

参考: http://tech.gmo-media.jp/post/45955244694/rails-rspec-model

62
62
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
62
62