嵌套资源自定义更新方法的路由问题

Routing issue on Nested Resource Custom Update Method

我正在 Rails 4 Ruby 2

中构建一个 Rails 应用程序

Background:

我在控制器中构建了自定义方法,允许我通过单击按钮更新 table。

我在构建按钮时得到了一些帮助,但是它只更新了嵌套元素中的第一个 ID。

我正在寻找所述按钮,当它被按下以仅定位其所在的订单项时。

The button/link:

<%= link_to "Remove Unit", [@call, responding], class: 'btn btn-danger btn-sm', method: :delete, confirm: "Are you sure you want to remove this unit?" %><%= link_to "Responding", unit_responding_update_call_responding_path(call_id: @call.id, id: @respondings.first.id), method: :patch %>

此按钮显示在 <%= @respondings.each do |responding| %> 中,并且应填充添加的每个行项目,以便在按下时更新该记录。

the controller action is:

    def unit_responding_update
    @call = Call.find(params[:call_id])
    @responding = Responding.find(params[:id])
    @responding.responding_tme = DateTime.now
    @responding.responding = "true"
    @responding.on_scene = "false"
    @responding.clear = "false"
    @responding.save!
      respond_to do |format|
      if @responding.save
        format.html { redirect_to @call, notice: "Responding time successfully updated." }
      else
        format.html { render action: 'edit' }
      end
    end
   end

Routes.rb is:

  resources :calls do
    resources :respondings, except: [:index], controller: 'calls/respondings' do
      member do
        patch :unit_responding_update
      end
    end
      resources :pings, except: [:index], controller: 'calls/pings'
      resources :agencies, except: [:index], controller: 'calls/agencies'
      resources :incidents, except: [:index], controller: 'calls/incidents'
      resources :complainants, except: [:index], controller: 'calls/complainants'
    end
  end

最后,自定义操作的 Rake Routes 输出是:

 unit_responding_update_call_responding PATCH  /calls/:call_id/respondings/:id/unit_responding_update(.:format) calls/respondings#unit_responding_update

我知道这可能只是一个小问题,我看过类似的 Whosebug 问题、treehouse 论坛和代码学院资源,但我无法解决这个问题。

在此先感谢您的帮助。如果您需要更多信息,请告诉我。

however it only updates the first id, in the nested element.

这是由于

<%= link_to "Responding", unit_responding_update_call_responding_path(call_id: @call.id, id: @respondings.first.id), method: :patch %>

因为此按钮显示在 <%= @respondings.each 中,请执行 |responding| %>,替换为

<%= link_to "Responding", unit_responding_update_call_responding_path(call_id: @call.id, id: responding.id), method: :patch %>