LoginSignup
3
2

More than 5 years have passed since last update.

Rails6 のちょい足しな新機能を試す6(BINDING環境変数編)

Posted at

はじめに

Rails 6 に追加されそうな新機能を試す第6段。 今回は rails server 実行時の BINDING 環境変数についてです。
HOST環境変数は、Rails 6.1 でサポートされなくなり、代わりに BINDING 環境変数を指定するように警告が出るようになりました。
記載時点では、Rails は 6.0.0.beta3 です。 gem install rails --prerelease でインストールできます。

$  rails --version
Rails 6.0.0.beta3u``

プロジェクトを作る

新機能を試すために、プロジェクトを作ってみます。

$ rails new sandbox_6_0_0b3
$ cd sandbox_6_0_0b3

試してみる

まずは、何も環境変数を指定していない状態で実行します。

$ bin/rails s
=> Booting Puma
=> Rails 6.0.0.beta3 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.2-p47), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000 # 環境変数の指定がないときの default は localhost
Use Ctrl-C to stop

次に HOST 環境変数を設定してから実行してみます。

$ env HOST=127.0.0.1 bin/rails s
DEPRECATION WARNING: Using the `HOST` environment to specify the IP is deprecated and will be removed in Rails 6.1. Please use `BINDING` environment instead. (called from <top (required)> at /app/sandbox_t/bin/rails:9)
=> Booting Puma
=> Rails 6.0.0.beta3 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.2-p47), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop

DEPRECATION WARNING が表示されました。

今度は、 BINDING 環境変数を指定してみます。

$ env BINDING=127.0.0.1 bin/rails s
=> Booting Puma
=> Rails 6.0.0.beta3 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.2-p47), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
Use Ctrl-C to stop

DEPRECATION WARNING なしで実行できました。

参考情報

3
2
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
3
2