已启动 rails 服务器,但无法加载本地主机页面
started the rails server but localhost page wont load
我启动了 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"
}
Completed 404 Not Found in 9ms (Views: 8.1ms | ActiveRecord: 0.0ms)
您的服务器和您的应用 运行 没问题;您的浏览器正在 http://localhost:3001 完美加载页面。
问题是您的应用返回 404 Not Found - 换句话说,Rails 无法将 controller/action 匹配到根路由。
查看您的 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
方法已定义)。
我启动了 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"
}
Completed 404 Not Found in 9ms (Views: 8.1ms | ActiveRecord: 0.0ms)
您的服务器和您的应用 运行 没问题;您的浏览器正在 http://localhost:3001 完美加载页面。
问题是您的应用返回 404 Not Found - 换句话说,Rails 无法将 controller/action 匹配到根路由。
查看您的 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
方法已定义)。