我正在做一个小任务来创建帖子并按类别划分它们。我一切正常,但在我的 index.html 中,我收到以下与我的链接相关的路由错误。
No route matches {:action=>"show", :controller=>"posts"}
No route matches {:action=>"edit", :controller=>"posts"}
undefined method `post_path' for #<#<Class:0x007fd3097f0ce0>:0x007fd3097c9370>
在 posts/index.html.haml 我有:
- @category.posts.each do |post|
%tr
%td= post.title
%td= post.description
%td= post.user_id
%td= post.category_id
%td= link_to 'Show', category_post_path //gives first error
%td= link_to 'Edit', edit_category_post_path //gives second error
%td= link_to 'Destroy', post,
:confirm => 'Are you sure?', :method => :delete //gives third error
在 routes.rb 我有:
resources :categories do
resources :posts
end
当我运行 rake 路线时,我得到:
categories_index GET /categories/index(.:format) categories#index
category_posts GET /categories/:category_id/posts(.:format) posts#index
POST /categories/:category_id/posts(.:format) posts#create
new_category_post GET /categories/:category_id/posts/new(.:format) posts#new
edit_category_postGET /categories/:category_id/posts/:id/edit(.:format) posts#edit
category_post GET /categories/:category_id/posts/:id(.:format) posts#show
PUT /categories/:category_id/posts/:id(.:format) posts#update
DELETE /categories/:category_id/posts/:id(.:format) posts#destroy
我的索引中有问题导致应用程序崩溃,因为我可以毫无问题地访问和查看这些内容:
/categories/:category_id/posts/:id (equivalent to show)
/categories/:category_id/posts/:id/edit (equivalent to edit)
有人可以帮我吗?先感谢您。