我希望能够一次显示我的SQL数据库五的值,然后按钮单击可以显示下五个,直到我显示所有课程。现在,这就是我试图显示它们的方式:
<%= form_for(Stc.new, action:'stcs#create') do |form| %>
<%= collection_check_boxes(:course_id, Course.all, :id, :title,{}) do
|form| %>
form.label { form.check_box }
<% end %>
<%= form.collection_select(:course_id, Course.all,:id, :title, {}, {
:multiple => false}) %>
<%= form.select(:semester, options_for_select([['Fall', 'Fall'],
['Spring', 'Spring'],['Summer', 'Summer']]), :id => 'sel1') %>
<%= form.select(:year, options_for_select([['2012', '2012'], ['2013',
'2013'], ['2014', '2014'], ['2015', '2015'], ['2016', '2016'], ['2017',
'2017']]), :id => 'sel2') %>
<%= form.select(:user_id, options_for_select([[1,@user.id]])) %>
<div class="actions">
<form id="my_sample_form">
</form>
<input type="submit" value="Submit" form="my_sample_form">
<% end %>
</div>
我想您想在这里进行分页,您可以使用宝石为此一个宝石是" will_paginate"宝石。
阅读有关https://github.com/mislav/will_paginate
您可以尝试使用Kaminari Gem进行分页。引用此:
https://github.com/kaminari/kaminari