はじめに
Rails 6 に追加されそうな新機能を試す第3段。 rails server
の -u
オプション機能です。
記載時点では、Rails は 6.0.0.beta3 です。 gem install rails --prerelease
でインストールできます。
$ rails --version
Rails 6.0.0.beta3
単純なCRUD機能をscaffold で作る
新機能を試すために、scaffold で単純なCRUD機能を作ってみます。
$ rails new sandbox_6_0_0b3
$ cd sandbox_6_0_0b3
$ rails g scaffold User name
従来の機能
rails server のオプションを調べてみます。
$ rails s --help
Usage:
rails server [puma, thin etc] [options]
Options:
-p, [--port=port] # Runs Rails on the specified port - defaults to 3000.
-b, [--binding=IP] # Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.
-c, [--config=file] # Uses a custom rackup configuration.
# Default: config.ru
-d, [--daemon], [--no-daemon] # Runs server as a Daemon.
-e, [--environment=name] # Specifies the environment to run this server under (development/test/production).
-P, [--pid=PID] # Specifies the PID file.
# Default: tmp/pids/server.pid
-C, [--dev-caching], [--no-dev-caching] # Specifies whether to perform caching in development.
[--early-hints], [--no-early-hints] # Enables HTTP/2 early hints.
-u
オプションはありません。
新機能
Rails 6.0.0beta3 で試してみます。
$ rails s --help
Usage:
rails server [thin/puma/webrick] [options]
Options:
-p, [--port=port] # Runs Rails on the specified port - defaults to 3000.
-b, [--binding=IP] # Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.
-c, [--config=file] # Uses a custom rackup configuration.
# Default: config.ru
-d, [--daemon], [--no-daemon] # Runs server as a Daemon.
-e, [--environment=name] # Specifies the environment to run this server under (development/test/production).
-u, [--using=name] # Specifies the Rack server used to run the application (thin/puma/webrick).
-P, [--pid=PID] # Specifies the PID file.
# Default: tmp/pids/server.pid
-C, [--dev-caching], [--no-dev-caching] # Specifies whether to perform caching in development.
[--early-hints], [--no-early-hints] # Enables HTTP/2 early hints.
[--log-to-stdout], [--no-log-to-stdout] # Whether to log to stdout. Enabled by default in development when not daemonized.
-u
オプションで rack サーバーを指定するようになってます。
では、試してみましょう。
$ rails s -u puma
=> 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
Use Ctrl-C to stop
webrickも試してみます。
$ rails s -u webrick
=> Booting WEBrick
=> Rails 6.0.0.beta3 application starting in development http://localhost:3000
=> Run `rails server --help` for more startup options
[2019-04-15 10:47:39] INFO WEBrick 1.4.2
[2019-04-15 10:47:39] INFO ruby 2.6.2 (2019-03-13) [x86_64-linux-musl]
[2019-04-15 10:47:39] INFO WEBrick::HTTPServer#start: pid=977 port=3000
せっかくなので、 thin
と falcon
も試してみます。 Gemfile に thin
と falcon
を追加します。
Gemfile
gem 'thin'
gem 'falcon'
bundle install
を実行した後、 thin
を試してみます。
$ rails s -u thin
=> Booting Thin
=> Rails 6.0.0.beta3 application starting in development http://localhost:3000
=> Run `rails server --help` for more startup options
Thin web server (v1.7.2 codename Bachmanity)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop
最後は falcon
です。
$ rails s -u falcon -b 0.0.0.0
=> Booting Falcon
=> Rails 6.0.0.beta3 application starting in development http://0.0.0.0:3000
=> Run `rails server --help` for more startup options
falcon
は -b
オプションを指定しないとエラーになりました。 falcon もそのまま使えるとわかったのは収穫でした。