2015-09-22 153 views
0

我正在使用rails 4與webrick服務器。開始通過使用rails s命令行服務器後,控制檯顯示以下內容:如何更改服務器根路徑

[email protected] ~/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 

我想改變服務器的根目錄從:

http://localhost:3000 

到:

http://localhost:3000/public 

回答

0

您需要通過傳遞正確的文檔根來配置webrick:

require 'webrick' 

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

謝謝,但這是一個文件? – stackow1

+0

檢查文檔:http://docs.ruby-lang.org/en/2.1.0/WEBrick.html –