0
我有一个表格,其中每个用户都有一个对应的复选框。点击一个按钮即可删除所选的下列内容。ActionController :: UrlGenerationError No嵌套资源的路由匹配
下面是用户下的嵌套资源,我在我的控制器中有一个销毁方法,当我做耙路由时,我可以看到相应的路由#destroy操作,但是当下列列表页面被加载时,它不会引发路由匹配错误。
routes.rb中:
resources :users do
resources :followings
resources :events
end
following_controller.rb:
class FollowingsController < ApplicationController
def index
@followings = Following.findFollowings(params.has_key?("user_id") ? params[:user_id] : current_user.id)
@following = Following.new
end
def destroy
Following.any_in(:following_id => params[:id]).destroy_all
render index
end
end
index.html.haml:
= form_for(@following, url: {action: 'destroy'}, :html => {:method => :delete, :role => 'form'}) do |f|
- @followings.each do |following|
= f.check_box "following_id"
= f.submit "Delete"
耙路线:
user_followings GET /users/:user_id/followings(.:format) followings#index
POST /users/:user_id/followings(.:format) followings#create
new_user_following GET /users/:user_id/followings/new(.:format) followings#new
edit_user_following GET /users/:user_id/followings/:id/edit(.:format) followings#edit
user_following GET /users/:user_id/followings/:id(.:format) followings#show
PATCH /users/:user_id/followings/:id(.:format) followings#update
PUT /users/:user_id/followings/:id(.:format) followings#update
DELETE /users/:user_id/followings/:id(.:format) followings#destroy
错误堆栈:
没有路由匹配{:action=>"destroy", :controller=>"followings", :user_id=>"540f5c6b7072610a4c040000"}
提取的源(左右线#9):
6 %ul
7 = render partial: "shared/npo_menu", locals: {item: 'followings'}
8 %section.following.notifications
9 = form_for(@following, url: {action: 'destroy'}, :html => {:method => :delete, :role => 'form'}) do |f|
10 .container
11 .row.manipulate
12 .pull-left
谢谢!
看起来像你的压痕可能会关闭,如果代码与您粘贴的代码相同。应该是一个缩进,然后following.check_box? – Kevin 2014-09-24 20:05:06
表单布局看起来有点不寻常。 你能解释为什么你在这个视图中使用两个不同的实例变量“@follow”和“@followings”?另外,为什么你在一个索引视图中渲染一个表单(并不是说它是错误的,但通常不是索引的用途)。 – Kevin 2014-09-24 20:24:32
@Kevin缩进在实际代码中是正确的,只是在这里粘贴了几行而不是整个哈姆。 “@followings”是要在索引页面上显示的列表。 “@following”是用户选择删除时的列表项目。 – Yeshasvi 2014-09-25 12:28:19