6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails6 のちょい足しな新機能を試す3(rails server -u編)

Last updated at Posted at 2019-04-15

はじめに

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

せっかくなので、 thinfalcon も試してみます。 Gemfile に thinfalcon を追加します。

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 もそのまま使えるとわかったのは収穫でした。

参考情報

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?