使用log: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(没有路由匹配[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运行rake路由
,这表明帮助和关于页面是针对{root} / static_pages / about而不是{root} / about 。我仍然不明白为什么教程给出了有关路线的信息,而这些路线看起来并不像预期的那样工作,并且欢迎任何进一步的评论,但我将其标记为已解决。
rake routes
由于您位于heroku,您需要运行
heroku run rake routes
类似于以下内容。
前缀动词URI模式控制器#动作
static_pages_about GET / static_pages / about(.:格式)static_pages#关于
因此,这表明您可以转到 www。 [heroku_app_name] .herokuapp.com / static_pages / about
它会将你带到你想要的页面。您也可以在视图中添加一个链接到页面。
<% = link_to(关于,static_pages_about_path)%>
这是所有人都知道的。但让我们讨论如何使用控制器操作: static_pages#about
,路径 / about
从
切换 routes.rb
中的以下内容:
至
获得static_pages / about,路径:/ about
或者
得到/ about,以:rabbits#about
您可以阅读更多关于路线
I am following the online version of Rails Tutorial. The Sample_app in chapter 3 works fine locally, but when pushed to Heroku, the home page is found but not the other pages. Running heroku logs after trying to see the About page gives me (along with much else) the error above:
2015-08-09T02:56:43.916991+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/about"):
My routes.rb file is
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
get 'static_pages/about'
end
I have followed the directions carefully. I tried deleting and recreating the Heroku file. I did web searches and tried some things to no avail. My gemfile is straight from the online version of the book, which is using current versions.
Solved: #thedanotto had me run heroku run rake routes
which showed that the help and about pages were directed to {root}/static_pages/about rather than {root}/about. I am still puzzled why the tutorial gives the about routes, which appear not to work as expected, and welcome any further comment, but I am marking this as solved.
Whenever I can't find a route, I run the terminal command
rake routes
Since you're on heroku you'll want to run
heroku run rake routes
Which will return something similar to the following.
Prefix Verb URI Pattern Controller#Action
static_pages_about GET /static_pages/about(.:format) static_pages#about
So that shows that you can go to www.[heroku_app_name].herokuapp.com/static_pages/about
And it will bring you to the page you want. You can also add a link to the page in a view by putting the following line of code within a view.
<%= link_to("About", static_pages_about_path) %>
That's all good stuff to know. But let's talk about using the controller action: static_pages#about
with the path /about
Switch the following in routes.rb
from
get 'static_pages/about'
to
get "static_pages/about", path:"/about"
or alternatively
get "/about", to: "rabbits#about"
You can read more about Routes here
这篇关于使用log:ActionController :: RoutingError(没有路由匹配[GET]“/ about”):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!