Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActionController::UrlGenerationError没有与嵌套资源匹配的路由_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails ActionController::UrlGenerationError没有与嵌套资源匹配的路由

Ruby on rails ActionController::UrlGenerationError没有与嵌套资源匹配的路由,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有一个表单,其中有一个用户的以下列表,每个列表都有一个对应的复选框。单击按钮后,选定的下列内容将被删除 Followers是users下的嵌套资源,我的控制器中有一个销毁方法,当我执行rake routes时,我可以看到与Followers Stroy操作相对应的路由,但当加载Followers列表页时,它不会抛出任何路由匹配错误 routes.rb: resources :users do resources :followings resources :even

我有一个表单,其中有一个用户的以下列表,每个列表都有一个对应的复选框。单击按钮后,选定的下列内容将被删除

Followers是users下的嵌套资源,我的控制器中有一个销毁方法,当我执行rake routes时,我可以看到与Followers Stroy操作相对应的路由,但当加载Followers列表页时,它不会抛出任何路由匹配错误

routes.rb:

    resources :users do
     resources :followings
     resources :events
    end
以下是_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
耙道:

    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=>followers,: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

谢谢

路由问题得到解决。对于多次删除,路由必须声明为集合。以下是有效的改变-

routes.rb

    resources :users do
      resources :followings do
        collection do
         delete 'destroy_multiple'
        end    
      end
      resources :events
   end 
以下是_controller.rb

    def destroy_multiple
      Following.any_in(:following_id => params[:id]).destroy_all

      respond_to do |format|
      format.html { redirect_to user_followings_path }
      format.json { head :no_content }
   end
index.haml.html

    = form_tag destroy_multiple_user_followings_path, method: :delete do 

如果代码与粘贴的代码相同,则缩进可能已关闭。应该是缩进,然后是后续。复选框?表单布局看起来有点不寻常。你能解释一下为什么在这个视图中使用两个不同的实例变量@following和@followings吗?另外,为什么要在索引视图中呈现表单,而不是说它是错误的,但通常不是索引的用途。@Kevin缩进在实际代码中是正确的,只是在这里粘贴了几行,而不是整个haml@以下是将在索引页上显示的列表@以下是当用户选择要删除的列表项时,列表项的设置。
    = form_tag destroy_multiple_user_followings_path, method: :delete do