Kaminari Pagination with Filter

时间:2014-01-09 15:17:31

标签: ruby-on-rails ajax kaminari

我在我的网站上使用Kaminari,并点击“加载更多”按钮以显示另外六个项目。它工作得很好但是当我尝试添加一个排序顺序时,它没有将params传递给link_to_next_page def,尽管我可以在html中看到它...

关于此问题的另一个问题是将params传递给link_to_next_page,但它没有什么区别。

示例:当我尝试按最低价格排序>最高价格前六个项目已经排序,但在“加载更多”时,排序顺序是随机的。

有人可以在这里提出建议吗?

感谢。

一些代码......

index.html.erb

 <div id="offers">
    <%= render :partial => @television_offers %>
  </div>

  <%= link_to_next_page @television_offers, 'Load More', :remote => true, :id=>"load_more_link", :params => params %>   </div>

index.js.erb的

$('#offers').append("<%= escape_javascript(render :partial => @television_offers)%>");
$('#load_more_link').replaceWith("<%= escape_javascript(link_to_next_page(@television_offers, 'Load More', :remote => true, :id=>'load_more_link', :params => params))%>");

application_helper.rb

def link_to_next_page(scope, name, options = {}, &block)
  param_name = options.delete(:param_name) || Kaminari.config.param_name
  link_to_unless scope.last_page?, name, {param_name => (scope.current_page + 1)},   options.merge(:rel => 'next') do
  block.call if block
  end
end

television_offers_controller.rb

def index

  @television_offers = TelevisionOffer.page(params[:page]).per(6)

  if params[:filter] == "large_screens"
    @television_offers = @television_offers.large_size
  elsif params[:filter] == "small_screens"
    @television_offers = @television_offers.small_size
  elsif params[:filter] == "price"

  if params[:order] == "asc"
    @television_offers = @television_offers.asc(:offer_price)
  else
    @television_offers = @television_offers.desc(:offer_price)
  end

  else
    @television_offers = @television_offers.best
  end
end

1 个答案:

答案 0 :(得分:0)

对于遇到相同问题的人来说,只需将kaminari更新为最新版本即可解决此问题