我正在尝试对以下数组进行分页。目前正在附加表格,但只有与第一页相同的记录:
def collection
@collection ||= begin
viewable_pupils.where(level: level, group_id: group_id).ordered
.map{ |p| Schools::Admin::PupilReportTableFacade.new(p, school.calendar_range_for_year_starting(report_start_year)) }
end
@collection = Kaminari.paginate_array(@collection).page(params[:page]).per(10)
end
helper_method :collection
我的观点如下:
<div class="container">
<%= render 'schools/admin/reporting/collection_partial' %>
</div>
<%= link_to 'Load More', school_reporting_load_more_path, remote: true, id: "load_more_link", class: 'btn btn-info' %>
部分呈现:
<% collection.each do |pupil| %>
<div class="well well--bordered well--skinny well--collapse-pad well--shadow">
<div class="marking-header marking-header--table marking-header--table-even">
<div class="marking-header__cell">
<%= pupil.first_name %>
</div>
<div class="marking-header__cell"><%= pupil.last_name %></div>
<div class="marking-header__cell" align="center">
<% pupil.histories.each do |history| %>
<% next unless school.calendar_range_for_year_starting(report_start_year).cover?(history[:created_at]) %>
<%= history[:year] %> <%= history[:level] %>
<%= history[:created_at] %>
<% end %>
</div>
<div class="marking-header__cell">
<%= "Total completed: #{pupil.pupil.activities_completed_year_starting(report_start_year)}" %></br>
<%= "(#{pupil.pupil.comprehensions_completed_year_starting(report_start_year)} x comprehensions)" unless pupil.pupil.comprehensions_completed_year_starting(report_start_year).zero? %></br>
<%= "(#{pupil.pupil.crosswords_completed_year_starting(report_start_year)} x crosswords)" unless pupil.pupil.crosswords_completed_year_starting(report_start_year).zero? %></br>
<%= "(#{pupil.pupil.debates_completed_year_starting(report_start_year)} x debates" unless pupil.pupil.debates_completed_year_starting(report_start_year).zero? %></br>
<%= "(#{pupil.pupil.word_definitions_completed_year_starting(report_start_year)} x word definitions" unless pupil.pupil.word_definitions_completed_year_starting(report_start_year).zero? %>
<div class="gems">
<% pupil.milestone_badges.each do |badge| %>
<%= image_tag image_path(badge.image), class: 'gem' %>
<% end %>
</div>
</div>
<div class="marking-header__cell">
<input type="checkbox" name="pupils[]" value="<%= pupil.id %>" class="tick-check" id="check-<%= pupil.id %>" data-behaviour="update-compare-count">
<label for="check-<%= pupil.id %>"></label>
<%= "Total this year: #{pupil.pupil.total_points_this_year}" %></br>
<%= "(Total all time: #{pupil.pupil.total_points})" %></br></br>
<%= "iHub points: #{pupil.pupil.score}" %></br>
<%= "Teacher Points: #{pupil.pupil.total_points_year_starting(report_start_year)}" %></br>
<%= "Words Read: #{pupil.pupil.words_read_year_starting(report_start_year)}" %></br>
</div>
</div>
</div>
<% end %>
最后我的ajax:
$('.container').append("<%= escape_javascript(render 'schools/admin/reporting/collection_partial')%>");
$('#load_more_link').replaceWith("<%= escape_javascript(link_to 'Load More', school_reporting_load_more_path, remote: true, id: "load_more_link", class: 'btn btn-info')%>");
如果需要更多信息,请问,我觉得我已经尝试了我能想到的一切。