Limit number of pages in will_paginate

后端 未结 3 1105
眼角桃花
眼角桃花 2021-01-05 16:38

So, when using Sphinx searches are limited to 1000 results. But, if there are more than 1000 results pagination links generated by will_paginate don\'t take thi

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 17:09

    I found the best solution was to do this:

    @results = Model.search(...)
    if @results.total_pages >= (1000/Model.per_page)
      class << @results; def total_pages; 1000/Model.per_page; end end
    end
    

    Where the 1000 is preferably not hardcoded :). This gets you the correct behaviour of the will_paginate view helper for free,

提交回复
热议问题