Skip to content

Instantly share code, notes, and snippets.

@gouf
Last active November 19, 2017 08:42
Show Gist options
  • Save gouf/916f2cb3370815eb62e5030453ae2dc9 to your computer and use it in GitHub Desktop.
Save gouf/916f2cb3370815eb62e5030453ae2dc9 to your computer and use it in GitHub Desktop.
各バージョンでrails new する

バージョンごとに新規作成するコマンドがあったらベンリかもしれないと思った

準備、コマンドの作成

各バージョンの Gemfile 作成

mkdir -p ~/.rails_versions/{3.0.0,4.0.0,5.0.0}
cd ~/.rails_versions/
# Gemfile をバージョンごとのディレクトリに作成
cat <<EOF
source 'https://rubygems.org'

gem 'rails', '3.0.0'
EOF > 3.0.0/Gemfile
# 同様に各バージョンのGemfile を作成

バージョンごとにbundle install

bundle install :

cd ~/.rails_versions/
for DIR in "3.0.0" "4.0.0" "5.0.0"; do cd $DIR; bundle; cd ..; done

コマンドの作成と有効化

~/.bashrc などに追記、有効化:

# 指定されたバージョンのディレクトリに移動し、bundle exec rails new を実行
rails_new() {
  VERSION=$1
  TARGET_PATH="${2:-.}" # 未指定なら「.」を代入

  cd ~/rails_versions/$VERSION # 指定バージョンのディレクトリに移動
  bundle exec rails new $TARGET_PATH
  cd - # 移動前のディレクトリに戻る
}

rails3() {
  rails_new '3.0.0' $2
}
rails4() {
  rails_new '4.0.0' $2
}
rails5() {
  rails_new '5.0.0' $2
}
source ~/.bashrc # 追記したコマンドの有効化

使う

rails3 new ~/rails3_projects/my_project
rails4 new ~/rails4_projects/my_project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment