markdown 各バージョンでrails新する

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 各バージョンでrails新する相关的知识,希望对你有一定的参考价值。

* [Rails開発環境の構築(複数バージョン共存可能)(Homebrew編) - Qiita](https://qiita.com/emadurandal/items/e43c4896be1df60caef0)
* [Ruby on Rails 4 - rails sでローカルサーバーを立ち上げたいのですが、以下のエラーが出てしまいます。(101118)|teratail](https://teratail.com/questions/101118)

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

# 準備、コマンドの作成

## 各バージョンの Gemfile 作成

```bash
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` :

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

## コマンドの作成と有効化

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

```bash
# 指定されたバージョンのディレクトリに移動し、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
}
```

```bash
source ~/.bashrc # 追記したコマンドの有効化
```

### 使う

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

---

* [bash - Using "${a:-b}" for variable assignment in scripts - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/122845/using-a-b-for-variable-assignment-in-scripts)

以上是关于markdown 各バージョンでrails新する的主要内容,如果未能解决你的问题,请参考以下文章

sh 头盔のバージョンを取得する

apache_conf CPIでPHPのバージョンを指定する

markdown rbenvによるバージョン切り替え

markdown 蟒蛇和jupyterバージョン管理など

markdown 加入されたリレーションで或句メソッドを使う

markdown rbenvで指定したバージョンの捆绑を使う