使用 RESTful 路径时发生 Rails 路由错误
我的 Rails 应用程序出现问题;它没有识别出应该存在的路线。我在 routes.rb 文件顶部添加了 resources :inquiries
,以确保我的查询能够进行基本的 CRUD 操作模型,旨在对我的网站的用户反馈进行分类。当我尝试渲染查询索引的视图时,我在浏览器中收到以下错误:
`No route matches {:action=>"show", :controller=>"inquiries"}`
来自控制台的简单 $ rake paths
显示这不是真的:`
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
sessions POST /sessions(.:format) {:action=>"create", :controller=>"sessions"}
new_session GET /sessions/new(.:format) {:action=>"new", :controller=>"sessions"}
session DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>"sessions"}
inquiries GET /inquiries(.:format) {:action=>"index", :controller=>"inquiries"}
POST /inquiries(.:format) {:action=>"create", :controller=>"inquiries"}
new_inquiry GET /inquiries/new(.:format) {:action=>"new", :controller=>"inquiries"}
edit_inquiry GET /inquiries/:id/edit(.:format) {:action=>"edit", :controller=>"inquiries"}
inquiry GET /inquiries/:id(.:format) {:action=>"show", :controller=>"inquiries"}
PUT /inquiries/:id(.:format) {:action=>"update", :controller=>"inquiries"}
DELETE /inquiries/:id(.:format) {:action=>"destroy", :controller=>"inquiries"}
about /about(.:format) {:action=>"about", :controller=>"pages"}
blog /blog(.:format) {:action=>"blog", :controller=>"pages"}
techniques /techniques(.:format) {:action=>"techniques", :controller=>"pages"}
contact /contact(.:format) {:action=>"new", :controller=>"inquiries"}
reviews /reviews(.:format) {:action=>"reviews", :controller=>"pages"}
signup /signup(.:format) {:action=>"new", :controller=>"users"}
signin /signin(.:format) {:action=>"new", :controller=>"sessions"}
signout /signout(.:format) {:action=>"destroy", :controller=>"sessions"}
root /(.:format) {:action=>"home", :controller=>"pages"}`
我应该提到它是我的 /inquiries/ 路线无法加载,并且不是单独的显示页面。 index.html.erb 文件如下:
'<h1>All Inquiries</h1>
<table>
<tr>
<th>Link</th>
<th>Name</th>
<th>Subject</th>
<th>Body</th>
</tr>
<%= @inquiries.each do |inquiry| %>
<tr>
<td><%= link_to inquiry.id, inquiry_path %></td>
<td><%= inquiry.name %></td>
<td><%= inquiry.subject %></td>
<td><%= inquiry.body[0..140] %>...</td>
</tr>
<% end %>
</table>`
对于应用程序找不到路线的原因有什么想法吗?预先感谢您的宝贵时间。
I am having a problem with my Rails application; it is not recognizing a route that should exist. I've included resources :inquiries
at the top of the routes.rb file, to ensure that there are the basic CRUD operations with my inquiries model, which is meant to catalog user-feedback for my website. When I try to render the view for the inquiry index, I get the following error in my browser:
`No route matches {:action=>"show", :controller=>"inquiries"}`
A simple $ rake routes
from the console shows that this isn't true: `
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
sessions POST /sessions(.:format) {:action=>"create", :controller=>"sessions"}
new_session GET /sessions/new(.:format) {:action=>"new", :controller=>"sessions"}
session DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>"sessions"}
inquiries GET /inquiries(.:format) {:action=>"index", :controller=>"inquiries"}
POST /inquiries(.:format) {:action=>"create", :controller=>"inquiries"}
new_inquiry GET /inquiries/new(.:format) {:action=>"new", :controller=>"inquiries"}
edit_inquiry GET /inquiries/:id/edit(.:format) {:action=>"edit", :controller=>"inquiries"}
inquiry GET /inquiries/:id(.:format) {:action=>"show", :controller=>"inquiries"}
PUT /inquiries/:id(.:format) {:action=>"update", :controller=>"inquiries"}
DELETE /inquiries/:id(.:format) {:action=>"destroy", :controller=>"inquiries"}
about /about(.:format) {:action=>"about", :controller=>"pages"}
blog /blog(.:format) {:action=>"blog", :controller=>"pages"}
techniques /techniques(.:format) {:action=>"techniques", :controller=>"pages"}
contact /contact(.:format) {:action=>"new", :controller=>"inquiries"}
reviews /reviews(.:format) {:action=>"reviews", :controller=>"pages"}
signup /signup(.:format) {:action=>"new", :controller=>"users"}
signin /signin(.:format) {:action=>"new", :controller=>"sessions"}
signout /signout(.:format) {:action=>"destroy", :controller=>"sessions"}
root /(.:format) {:action=>"home", :controller=>"pages"}`
I should mention that it is my /inquiries/ route that fails to load, and not an individual show page. The index.html.erb file is as follows:
'<h1>All Inquiries</h1>
<table>
<tr>
<th>Link</th>
<th>Name</th>
<th>Subject</th>
<th>Body</th>
</tr>
<%= @inquiries.each do |inquiry| %>
<tr>
<td><%= link_to inquiry.id, inquiry_path %></td>
<td><%= inquiry.name %></td>
<td><%= inquiry.subject %></td>
<td><%= inquiry.body[0..140] %>...</td>
</tr>
<% end %>
</table>`
Any ideas on why the application can't find the route? Thanks in advance for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是由行
<%= link_toquery.id,inquiry_path %>
通过使用
inquiry_path
,您应指定一个查询来显示。所以路径应该是:如果您使用 RESTful 路径,您可以将其简化为:
I think the problem is created by the line
<td><%= link_to inquiry.id, inquiry_path %></td>
By using
inquiry_path
, you should appoint an inquiry to be shown. So the path should be:If you are using RESTful paths, you could simplify it to: