在我的应用程序中,我使用javascript过滤场地记录,并在场地索引页面上显示部分内容。但是,当我设置了will_paginate时,过滤器形式会中断,它们都可以单独工作但不能一起工作。我在这里做错了什么?
jQuery脚本
<script>
$(function() {
$(".venuetypes").buttonset();
});
$(function() {
$(".areas").buttonset();
});
$(function() {
$( "button, input:submit, a", ".filter_form_button" ).button();
$( "a", ".form_filter_button" ).click(function() { return false; });
});
</script>
过滤表格
<div class="filter_options_container">
<%= form_tag '', :method => :get, :id => 'filter_form' do %>
<fieldset class="filter_form_fieldset venuetypes">
<% Venuetype.all.each do |v| %>
<p class="venuetype_check"><%= check_box_tag 'venuetypes[]', v.id, false, :id => "venuetype-#{v.id}" %>
<label for="venuetype-<%= v.id %>"><%= v.name %></label></p>
<% end %>
</fieldset>
<fieldset class="filter_form_fieldset areas">
<% Area.all.each do |a| %>
<p class="area_check"><%= check_box_tag 'areas[]', a.id, false, :id => "area-#{a.id}" %>
<label for="area-<%= a.id %>"><p1><%= a.name %></p1></label></p>
<% end %>
</fieldset>
<div class="filter_form_button">
<p2><input type="submit" value="Filter"/></p2>
</div>
<% end %>
</div>
场地管理员
def index
if
@venues = Venue.with_type(params[:venuetypes]).with_area(params[:areas]).order("average_rating DESC").all
else
@venues = Venue.all
end
@venues = Venue.paginate :all, :page => params[:page], :per_page => 15
end
非常感谢任何帮助,非常感谢!
答案 0 :(得分:1)
当我认为你试图为该查询添加分页时,你正在覆盖@venues变量。试试这个:
def index
if
@venues = Venue.with_type(params[:venuetypes]).with_area(params[:areas]).order("average_rating DESC").all
else
@venues = Venue.all
end
@venues = @venues.paginate :per_page => 15, :page => params[:page]
end
答案 1 :(得分:0)
您正在添加额外的逗号。
应该是这样的:
Model.pagination :per_page => 15, :page => params[:page]
所以你应该这样:
def index
if
@venues = Venue.with_type(params[:venuetypes]).with_area(params[:areas]).order("average_rating DESC").all
else
@venues = Venue.all
end
@venues = Venue.paginate :per_page => 15, :page => params[:page]
end