我想在我的数据库上更新一个模型。如果用户选中该复选框,则该复选框不能再次出现在视图中。
我有这样的观点:
<%= form_tag( riepilogo_path, method: "post", id: "sel") do %>
<%= hidden_field_tag "sala", params[:sala] %>
<%= hidden_field_tag "spectacle_id", params[:spectacle_id] %>
<%= hidden_field_tag "num", params[:num] %>
<table>
<tr>
<th></th>
<th>Numero</th>
</tr>
<% for posti in @postis %>
<tr>
<td><%= check_box_tag "posti_ids[]", posti.id %></td>
<td><%=h posti.numero %></td>
</tr>
<% end %>
</table>
<%= submit_tag "OK", id: "sub"%>
<% end %>Postis的控制器是这样的:
class PostisController < ApplicationController
def index
@postis = Posti.where(:stato => "unchecked" , :spectacle_id => params[:spectacle_id] , :hall_num => params[:sala])
end
def posti_multiple
@postis = Posti.find(params[:posti_ids])
end
end在Posti的模型中,我有属性:spectacle_id、hall_num、seat(整数)和stato (:default => "unchecked")。
当他提交时,座位会被加载到posti_ids[]中。我想将posti_ids中存在的座位从“未选中”更新为“选中”。
发布于 2014-05-29 02:26:41
根据您的评论,您试图在Array.So上执行update_column是错误的
#
的未定义方法`update_column:0xb881584
在这里,@postis returns.You应该是这样给它的
Posti.update_column(stato: "checked")https://stackoverflow.com/questions/23917154
复制相似问题