Rails 教程 sample_app 在 Heroku 中失败,日志为:ActionController::RoutingError(没有路由匹配 [GET]“/about”):
Rails Tutorial sample_app fails in Heroku with log: ActionController::RoutingError (No route matches [GET] "/about"):
我正在关注 Rails 教程的在线版本。第 3 章中的 Sample_app 在本地工作正常,但是当推送到 Heroku 时,找到了主页,但找不到其他页面。 运行 在尝试查看“关于”页面后,heroku 记录了上面的错误(以及其他许多错误):
2015-08-09T02:56:43.916991+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/about"):
我的 routes.rb 文件是
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
get 'static_pages/about'
end
我已仔细按照说明进行操作。我尝试删除并重新创建 Heroku 文件。我做了网络搜索并尝试了一些无济于事的事情。我的 gemfile 直接来自本书的在线版本,它使用的是当前版本。
已解决: #thedanotto 让我 运行 heroku run rake routes
这表明帮助和关于页面被定向到 {root}/static_pages/about而不是 {root}/about。我仍然很困惑为什么教程给出了 about 路线,这似乎没有按预期工作,欢迎任何进一步的评论,但我将其标记为已解决。
如果它在本地运行良好,我假设您已经正确设置了控制器、视图等。
您是否确保提交所有那些必要的更改然后推送?
例如
git add .
git commit -am "Added route"
git push heroku master
您是否使用以下 URL 访问关于页面?
http://YourHerokuAppName.herokuapp.com/static_pages/about
[将 "YourHerokuAppName" 替换为您的 Heroku 应用名称]
每当找不到路线时,我 运行 终端命令
rake routes
由于您使用的是 heroku,因此您需要 运行
heroku run rake routes
这将 return 类似于以下内容。
Prefix Verb URI Pattern Controller#Action
static_pages_about GET /static_pages/about(.:format) static_pages#about
这表明您可以转到 www.[heroku_app_name].herokuapp.com/static_pages/about
它将带您到所需的页面。您还可以通过将以下代码行放入视图中,将 link 添加到视图中的页面。
<%= link_to("About", static_pages_about_path) %>
这些都是值得了解的好东西。但是让我们谈谈使用控制器操作:static_pages#about
和路径 /about
将routes.rb
中的以下内容从
切换
get 'static_pages/about'
至
get "static_pages/about", path:"/about"
或者
get "/about", to: "rabbits#about"
您可以阅读更多关于 Routes here
我正在关注 Rails 教程的在线版本。第 3 章中的 Sample_app 在本地工作正常,但是当推送到 Heroku 时,找到了主页,但找不到其他页面。 运行 在尝试查看“关于”页面后,heroku 记录了上面的错误(以及其他许多错误):
2015-08-09T02:56:43.916991+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/about"):
我的 routes.rb 文件是
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
get 'static_pages/about'
end
我已仔细按照说明进行操作。我尝试删除并重新创建 Heroku 文件。我做了网络搜索并尝试了一些无济于事的事情。我的 gemfile 直接来自本书的在线版本,它使用的是当前版本。
已解决: #thedanotto 让我 运行 heroku run rake routes
这表明帮助和关于页面被定向到 {root}/static_pages/about而不是 {root}/about。我仍然很困惑为什么教程给出了 about 路线,这似乎没有按预期工作,欢迎任何进一步的评论,但我将其标记为已解决。
如果它在本地运行良好,我假设您已经正确设置了控制器、视图等。
您是否确保提交所有那些必要的更改然后推送?
例如
git add .
git commit -am "Added route"
git push heroku master
您是否使用以下 URL 访问关于页面? http://YourHerokuAppName.herokuapp.com/static_pages/about
[将 "YourHerokuAppName" 替换为您的 Heroku 应用名称]
每当找不到路线时,我 运行 终端命令
rake routes
由于您使用的是 heroku,因此您需要 运行
heroku run rake routes
这将 return 类似于以下内容。
Prefix Verb URI Pattern Controller#Action
static_pages_about GET /static_pages/about(.:format) static_pages#about
这表明您可以转到 www.[heroku_app_name].herokuapp.com/static_pages/about
它将带您到所需的页面。您还可以通过将以下代码行放入视图中,将 link 添加到视图中的页面。
<%= link_to("About", static_pages_about_path) %>
这些都是值得了解的好东西。但是让我们谈谈使用控制器操作:static_pages#about
和路径 /about
将routes.rb
中的以下内容从
get 'static_pages/about'
至
get "static_pages/about", path:"/about"
或者
get "/about", to: "rabbits#about"
您可以阅读更多关于 Routes here