【发布时间】:2016-03-03 14:30:48
【问题描述】:
我在 Rails 4 Ruby 2 中构建 Rails 应用程序
背景:
我在控制器中构建了一个自定义方法,允许我通过单击按钮来更新表格。
我在构建按钮时得到了一些帮助,但是它只更新嵌套元素中的第一个 id。
当我按下按钮以仅定位其所在的订单项时,我正在寻找所述按钮。
按钮/链接:
<%= 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| %> 中,并且应该填充添加的每个行项目,以便在按下时可以更新该记录。
控制器动作是:
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 是:
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
我知道这可能只是一个小问题,我查看了类似的 StackOverflow 问题、树屋论坛和代码学院资源,但我终生无法解决这个问题..
提前感谢您的帮助。如果您需要任何进一步的信息,请告诉我。
【问题讨论】:
标签: ruby ruby-on-rails-4 routes nested-routes