0

我開始Rails服務器開始鐵軌服務器,但本地主機頁面不會加載

$ bundle exec rails s -p 3001 
=> Booting WEBrick 
=> Rails 4.2.5 application starting in development on http://localhost:3001 
=> Run `rails server -h` for more startup options 
=> Ctrl-C to shutdown server 
[2016-11-03 19:29:30] INFO WEBrick 1.3.1 
[2016-11-03 19:29:30] INFO ruby 2.2.5 (2016-04-26) [x86_64-darwin15] 
[2016-11-03 19:29:30] INFO WEBrick::HTTPServer#start: pid=30949 port=3001 

但是當我去到http://localhost:3001我得到錯誤:該本地主機頁面無法找到

這是數據我看到終端後,我去http://locahhost:3001 任何想法是什麼錯?

{ 
    "timestamp": "2016-11-03T23:35:40Z", 
    "severity": "DEBUG", 
    "type": "none", 
    "message": " \u001b[1m\u001b[36mSQL (57.9ms)\u001b[0m \u001b[1mUSE [peak]\u001b[0m" 
} 
{ 
    "timestamp": "2016-11-03T23:35:40Z", 
    "severity": "INFO", 
    "type": "database.query", 
    "request_id": "67b064b7-f6a3-414e-9a39-da4f851fc8dd", 
    "connection_id": "70230967245540", 
    "event": "SQL", 
    "query_id": "a15f740d4daad1a81dbc7e0df1ccf3e5", 
    "query": "USE [peak]", 
    "duration": "58.3" 
} 
{ 
    "timestamp": "2016-11-03T23:35:40Z", 
    "severity": "INFO", 
    "type": "none", 
    "message": "Processing by HomeController#index as HTML" 
} 
{ 
    "timestamp": "2016-11-03T23:35:40Z", 
    "severity": "INFO", 
    "type": "none", 
    "message": " Rendered text template (0.0ms)" 
} 
{ 
    "timestamp": "2016-11-03T23:35:40Z", 
    "severity": "INFO", 
    "type": "view.render", 
    "request_id": "67b064b7-f6a3-414e-9a39-da4f851fc8dd", 
    "template": "text template", 
    "layout": null, 
    "duration": "0.4" 
} 
{ 
    "timestamp": "2016-11-03T23:35:40Z", 
    "severity": "INFO", 
    "type": "none", 
    "message": "Completed 404 Not Found in 9ms (Views: 8.1ms | ActiveRecord: 0.0ms)" 
} 
{ 
    "timestamp": "2016-11-03T23:35:40Z", 
    "severity": "INFO", 
    "type": "application.request", 
    "request_id": "67b064b7-f6a3-414e-9a39-da4f851fc8dd", 
    "method": "GET", 
    "status": 404, 
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36", 
    "referrer": null, 
    "forwarded_for": null, 
    "url_scheme": "http", 
    "url_host": "localhost", 
    "url_port": "3001", 
    "url_path": "/", 
    "url_query": null, 
    "rails_controller": "home", 
    "rails_action": "index", 
    "clean_path": "/", 
    "remote_ip": "::1", 
    "remote_host": "::1", 
    "duration": "1108.02", 
    "message": "Not Found", 
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", 
    "content_type": "text/plain; charset=utf-8" 
} 
+0

您的日誌中包含「在9毫秒內完成404未找到」,它看起來像您的應用程序運行得很好,但您提供的路徑沒有路徑。你期望看到什麼? – Jonah

+0

你的路線有什麼?最後一條消息說「home#index」是「未找到」,所以路由是一個開始尋找的好地方......然後......你有一個帶有索引操作的家庭控制器(是下一個看看的地方) 。 –

回答

1
Completed 404 Not Found in 9ms (Views: 8.1ms | ActiveRecord: 0.0ms) 

你的服務器和你的應用程序正在運行的罰款;您的瀏覽器正在加載頁面http://localhost:3001非常好。

問題是,您的應用程序正在返回404 Not Found - 換句話說,Rails無法將控制器/操作與根路由匹配。

查看您的config/routes.rb文件。你應該有root定義的路由,如

root :to => 'home#index' 

如果你直接訪問的路徑(如http://localhost:3001/example/path),請確保您擁有該定義的路由:

get 'example/path', :to => 'controller#action' 

最後,請確保相關控制器存在並且具有用於您的路線映射到的動作的方法定義(例如,對於root示例,確保存在app/controllers/home_controller.rb並且其定義了index方法)。

+0

謝謝。我檢查了routs.rb,並且他們添加了一個名稱空間,因此只需在url中使用名稱空間 – User7354632781

相關問題