使用复选框/错误数量的参数rails 4更新一个表单中的多个记录
我一直在通过教程/论坛笨拙地试图弄清楚如何使用复选框更新多个方法。
如果日期可用,我需要能够列出我的“事件”并检查或取消选中它们。 我想在一个表格上这样做。 我知道这是可能的,但是我终于在没有让它工作的时候来到这里。
使用我发布的代码,我得到“错误的参数数量,2比1”错误。
我试过这些信息来源: http : //railscasts.com/episodes/52-update-through-checkboxes http://discuss.codeschool.io/t/surviving-apis-with-rails-posting-multiple-records / 4776/4 http://railscasts.com/episodes/165-edit-multiple-revised
这就是我在的地方
的routes.rb
resources :events do collection do put :verified post :make_events end end
events_controller.rb
def verified if Event.update_all(["available", true], :id => params[:event_ids]) redirect_to step2_path(:pid => @project.id, :u => current_user.id) else end end
show.html.erb
@project.id ), method: :put do %> event.available %>