各バージョンでrails new する
バージョンごとに新規作成するコマンドがあったらベンリかもしれないと思った
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
:
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