Search code examples
ruby-on-railsruby-on-rails-4webrick

How to change server root path


I am using rails 4 with server webrick. After starting the server via command line using rails s, the console displays the following:

kalinin@kalinin ~/rails/admin_book $ rails s
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on c
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-09-22 15:43:27] INFO  WEBrick 1.3.1
[2015-09-22 15:43:27] INFO  ruby 2.0.0 (2014-11-13) [x86_64-linux]
[2015-09-22 15:43:27] INFO  WEBrick::HTTPServer#start: pid=14160 port=3000

I want to change server root from:

http://localhost:3000

to:

http://localhost:3000/public

Solution

  • You need to configure webrick by passing the correct document root:

    require 'webrick'
    
    root = File.expand_path '~/public'
    server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root