LoginSignup
1
1

More than 5 years have passed since last update.

Railsの起動オプションの省略方法【備忘録】

Last updated at Posted at 2017-02-24

はじめに

どこかで、Railsの起動オプションの省略方法を調べたのだけども、
調べたサイトがどこかに行ってしまったので、個人的なメモを残す感じで

ちなみにRailsのバージョンは4.2.7.1です。

起動オプションの省略

普段は下記のようなコマンドうっています。。。がオプションつけるのめんどくさい
(ポートはあまり変えませんが...)
bundle exec rails s -b 0.0.0.0 -p 3001

そんなわけで、"Railsアプリ名"/config/boot.rbをいじります。

boot.rb
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' # Set up gems listed in the Gemfile.

# ここから追加する
require 'rails/commands/server'
module Rails
    class Server
        def default_options
            super.merge(Host: '0.0.0.0', Port: 3001)
        end
    end
end
# 追加ここまで

するとbundle exec rails sを入力するだけで下記のようにRailsのサーバーが起動します。

PS C:\hogehoge\demo-app> bundle exec rails s
=> Booting WEBrick
=> Rails 4.2.7.1 application starting in development on http://0.0.0.0:3001
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2017-02-24 19:17:50] INFO  WEBrick 1.3.1
[2017-02-24 19:17:50] INFO  ruby 2.0.0 (2015-12-16) [x64-mingw32]
[2017-02-24 19:17:50] INFO  WEBrick::HTTPServer#start: pid=45224 port=3001

もう忘れないようにしないと...

1
1
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
1
1