Kaminari - 无法根据页面限制动态选择
Kaminari - can't get dynamically selected per page limit
这是我的代码。
控制器:
def bisac_main_counts
q = "
MATCH (b:Bisac) WHERE (b.bisac_code =~ '.*000000')
WITH b, size((b)<-[:INCLUDED_IN]-()) as wokas_count
RETURN b.bisac_code as bisac_code, b.bisac_value as bisac_value, wokas_count
ORDER BY b.bisac_code
;"
@result = Neo4j::Session.current.query(q).to_a
if params[:limit]
@result = Kaminari.paginate_array(@result).page(params[:page]).per(params[:limit])
else
@result = Kaminari.paginate_array(@result).page(params[:page])
end
end
查看:
<%= render 'home/main_links' %>
<%= paginate @result %>
<%= render 'bisac_counts' %>
<%= form_tag bisac_main_counts_path, method: :get do %>
<%= select_tag :limit, options_for_select([5, 10, 15, 20, 25], selected: params[:limit] || 25) %>
<% end %>
部分:
<table>
<thead>
<tr>
<th>Bisac Code</th>
<th>Bisac Value</th>
<th>Wokas Count</th>
</tr>
</thead>
<tbody>
<% @result.each do |record| %>
<tr>
<td><%= record.bisac_code %></td>
<td><%= record.bisac_value%></td>
<td><%= record.wokas_count %></td>
</tr>
<% end %>
</tbody>
</table>
显然 params[:limit]
未在视图中设置。它始终为空。正在更改页面。
我做错了什么?
缺少的是更改限制的表格和触发它的方法。
以下是更改(仅在视图中):
<%= render 'home/main_links' %>
<%= paginate @result %>
<%= render 'bisac_counts' %>
<%= form_tag bisac_main_counts_path, method: :get, id: 'limit_form' do %>
<%= select_tag :limit, options_for_select([5, 10, 15, 20, 25], selected: params[:limit] || 10) %>
<% end %>
<script type="text/javascript" >
$(function(){
$('#limit').change(
function() {
$('#limit_form').submit();
});
});
</script>
这是我的代码。
控制器:
def bisac_main_counts
q = "
MATCH (b:Bisac) WHERE (b.bisac_code =~ '.*000000')
WITH b, size((b)<-[:INCLUDED_IN]-()) as wokas_count
RETURN b.bisac_code as bisac_code, b.bisac_value as bisac_value, wokas_count
ORDER BY b.bisac_code
;"
@result = Neo4j::Session.current.query(q).to_a
if params[:limit]
@result = Kaminari.paginate_array(@result).page(params[:page]).per(params[:limit])
else
@result = Kaminari.paginate_array(@result).page(params[:page])
end
end
查看:
<%= render 'home/main_links' %>
<%= paginate @result %>
<%= render 'bisac_counts' %>
<%= form_tag bisac_main_counts_path, method: :get do %>
<%= select_tag :limit, options_for_select([5, 10, 15, 20, 25], selected: params[:limit] || 25) %>
<% end %>
部分:
<table>
<thead>
<tr>
<th>Bisac Code</th>
<th>Bisac Value</th>
<th>Wokas Count</th>
</tr>
</thead>
<tbody>
<% @result.each do |record| %>
<tr>
<td><%= record.bisac_code %></td>
<td><%= record.bisac_value%></td>
<td><%= record.wokas_count %></td>
</tr>
<% end %>
</tbody>
</table>
显然 params[:limit]
未在视图中设置。它始终为空。正在更改页面。
我做错了什么?
缺少的是更改限制的表格和触发它的方法。 以下是更改(仅在视图中):
<%= render 'home/main_links' %>
<%= paginate @result %>
<%= render 'bisac_counts' %>
<%= form_tag bisac_main_counts_path, method: :get, id: 'limit_form' do %>
<%= select_tag :limit, options_for_select([5, 10, 15, 20, 25], selected: params[:limit] || 10) %>
<% end %>
<script type="text/javascript" >
$(function(){
$('#limit').change(
function() {
$('#limit_form').submit();
});
});
</script>