我的Rails应用程序出现问题;它没有识别应存在的路径。我已将resources :inquiries
添加到 routes.rb 文件的顶部,以确保我的查询模型有基本的CRUD操作,这意味着为我的网站编制用户反馈的目录。当我尝试渲染查询索引的视图时,我在浏览器中收到以下错误:
`No route matches {:action=>"show", :controller=>"inquiries"}`
来自控制台的简单$ rake routes
表明这不是真的:`
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"}`
我应该提一下,我的 / queries / 路由无法加载,不个别展示页面。 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>`
有关应用程序无法找到路线的任何想法?在此先感谢您的时间。
答案 0 :(得分:3)
我认为问题是由行<td><%= link_to inquiry.id, inquiry_path %></td>
使用inquiry_path
,您应该指定要显示的查询。所以路径应该是:
<td><%= link_to inquiry.id, inquiry_path(inquiry) %></td>
如果您使用的是RESTful路径,则可以将其简化为:
<td><%= link_to inquiry.id, inquiry %></td>