【发布时间】:2017-01-18 00:10:33
【问题描述】:
我正在实现一种方法来隐藏表中的记录,但不通过按钮从我的数据库中删除。我在设置为 false 的表中添加了一个列“revision_active”布尔属性。使用视图条件可以显示仅设置为 true 的记录。
我的按钮(通过复选框将属性设置为 true):
<%= form_tag update_multiple_homeworks_path(:revision_active => true), method: :put do %>
....
<td><%= check_box_tag "homework[id][]", homework.id, checked = false %></td>
....
<%= submit_tag "Add to Bucket", :remote => true, :class => 'smallMobileRight button text-left' %>
在我的路线中:
resources :homeworks do
collection do
put 'update_multiple'
end
end
在我的控制器中:
def update_multiple
if params[:homework][:id]
@homework_ids = params[:homework][:id]
@homework_ids.each do |id|
Homework.revision_active = true
end
else
redirect_to homeworks_homework_details_path
end
respond_to do |format|
flash[:notice] = "Added to your Bucket!"
format.html { redirect_to homeworks_homework_details_path }
format.json { head :no_content }
format.js { render :layout => false }
end
end
参数
...
"_method"=>"put",
"authenticity_token"=>"blah",
"homework"=>{"id"=>["107"]},
"commit"=>"Add to Bucket",
"revision_active"=>"true",
"id"=>"update_multiple"}
点击按钮时出错:
Couldn't find Homework with 'id'=update_multiple
有什么想法吗?我没有捕捉到 ID 数组,控制器出错?谢谢。
【问题讨论】:
标签: ruby-on-rails view controller