无法捕获剩余页面的check_box对角,请帮助我。
我只能抓到提交的页面
我的观点
<table id="associations" class="table table-striped table-bordered ">
<thead>
<th>Check</th>
<th>Logo</th>
</thead>
<tbody>
<% @benefits.each do |benefit|%>
<%@selected_benefits = AssocBenefit.where(:benefit_id=>benefit.id, :association_id => @association.id, :status => true).first%>
<tr>
<td>
<%#= check_box_tag :car, :value => 2, :checked => (f.sex == 2) %>
<%if @selected_benefits.present?%>
<%= hidden_field_tag 'benefits1[]', benefit.id %>
<%= check_box_tag 'benefits[]', benefit.id, :checked => (benefit.id == @selected_benefits.id)%>
</td>
<%else%>
<%= hidden_field_tag 'benefits1[]', benefit.id %>
<%= check_box_tag 'benefits[]', benefit.id%></td>
<%end%>
<td><%= image_tag benefit.image(:thumb) %></td>
<td><%= benefit.benefits_name%></td>
<%end%>
</tbody>
</table> 我的控制器
def save_choose_benefits
assoc_benefits = AssocBenefit.where.not(:benefit_id => params[:benefits]).all if params[:benefits1]
assoc_benefits.delete_all
unless params[:benefits].blank?
params[:benefits].each do |d|
ss= AssocBenefit.where(:benefit_id => d).first
if ss.blank?
assoc_benefits = AssocBenefit.new(:benefit_id => d ,:association_id => params[:association_id], :status=>"true")
if assoc_benefits.valid?
assoc_benefits.save
end
end
end
end
redirect_to associations_list_path ,:notice => "Successfully applied"
end这是我的剧本
<script>
$(document).ready(function()
{
$('#associations').dataTable();
}
);
</script>我安装了gem jquery-datatable,也安装了jquery-turbolink来传递params,但是没有运气通过第二页的params等等。
请帮我解决这些问题
谢谢
发布于 2016-04-26 16:43:46
<table id="associations" class=" display table table-striped table-bordered ">
<thead>
<th>Check</th>
<th>Logo</th>
</thead>
<tbody>
<% @benefits.each do |benefit|%>
<%@selected_benefits = AssocBenefit.where(:benefit_id=>benefit.id, :association_id => @association.id, :status => true).first%>
<tr>
<td>
<%if @selected_benefits.present?%>
<%= hidden_field_tag 'benefits1[]', benefit.id, :unchecked => (benefit.id != @selected_benefits.id) %>
<%= check_box_tag 'benefits[]', benefit.id, :checked => (benefit.id == @selected_benefits.id) %>
</td>
<%else%>
<%= hidden_field_tag 'benefits1[]', benefit.id %>
<%= check_box_tag 'benefits[]', benefit.id %></td>
<%end%>
<td><%= image_tag benefit.image(:thumb) %></td>
</tr>
<%end%>
</tbody>
</table>
<%= submit_tag "Apply", :id=>"assoc_apply"%>
<script>
$(document).ready(function() {
var table = $('#associations').DataTable({
responsive: true,
retrieve: true,
sPaginationType: "full_numbers",
bJQueryUI: true});
$('#assoc_apply').click( function() {
var data = table.$('input, select').serialize();
var association_id = "<%=@association.id%>";
window.location.href='/benefits/save_choose_benefits?' + data +"&association_id=" + association_id;
} );
} );
https://stackoverflow.com/questions/36099952
复制相似问题