will-paginate

Ajax request with will_paginate Rails 4

百般思念 提交于 2019-12-23 17:53:26
问题 I've been reading through some posts on SO to see how others are handling this and the implementation i am using is almost there but fails after the third link requested, what happens is the page is reloaded as opposed to firing the ajax request. I have also removed Turbolinks but that hasn't made a difference. This is my setup and I think the js is failing somewhere and as my jQuery is not that strong I was hoping someone could help out Index.html.erb <div class="facebook_ajax"> <%= render

will_paginate show the last page by default (keeping chronological order)

微笑、不失礼 提交于 2019-12-23 13:02:07
问题 I'm building an index page where I need to display results which have a date, ordered chronologically (from the earliest date to the newest one), but I need to always show the last page by default. I can't use a DESC order for the date because it would defeat the whole purpose of what I need this for =(. TL;DR: I need to show a paginated log list, sorted by date ascending, but starting in the last page. Is this possible with will_paginate? Thanks! 回答1: You can build your query, get the total

Paginate through a randomized list of blog posts using will_paginate

爱⌒轻易说出口 提交于 2019-12-23 11:49:10
问题 I want to give users the ability to page through my blog posts in random order. I can't implement it like this: @posts = Post.paginate :page => params[:page], :order => 'RANDOM()' since the :order parameter is called with every query, and therefore I risk repeating blog posts. What's the best way to do this? 回答1: RAND accepts a seed in MySQL: RAND(N) From the MySQL docs: RAND(), RAND(N) Returns a random floating-point value v in the range 0 <= v < 1.0. If a constant integer argument N is

Rails paginate existing array of ActiveRecord results

我与影子孤独终老i 提交于 2019-12-23 09:37:30
问题 I generally use will_paginate for the pagination in my app, but have hit a stumbler on my search feature. I'm using Thinking Sphinx for doing my full-text search, which returns results paginated. The problem I'm having is that after I've received the results from Thinking Sphinx, I need to merge them with some other results and re-order them. Once I've finished processing them I have an Array of results that is very different from the original from TS. As there could be 1000+ results in this

Rails 4 pagination with dynamic data

冷暖自知 提交于 2019-12-23 09:25:56
问题 Hi I have a rails4 app using pagination with the will_paginate gem. Is there a way to handle pagination with objects created very often? If you call the first page and right after that the page 2, considering new objects are created in the meantime, it is going to mess data (the offset in the sql request is for example going to call almost the same data as the first page). Is there a way to use pagination with rapidly changing dynamic data? Thx for your suggestions 回答1: Also, you could use

How can I make a POST call instead of GET call with will_paginate?

微笑、不失礼 提交于 2019-12-23 05:32:11
问题 How can I make a post call instead of get call when i am paginating through pages using rails gem will_paginate? In controller I have @bills = Bill.where(some_condition) # returns collection @bills = @bills.paginate(:page => params[:page], :per_page => 5) In view have used a table structure and at the end, have used <%will_paginate%> , hence page 1 is showing up, but when I click on "next" or "page 2" then GET req. goes, I want to change it to POST call, is it possible? 回答1: I agree with

Rails WillPaginate::Collection not paginating Array

一笑奈何 提交于 2019-12-23 04:08:42
问题 An existing array vparray is being generated, then sorted by a non-db column rate . It then needs to be paginated : @vps = vparray.sort_by{|e| e.rate} @vps = WillPaginate::Collection.create(1, 10, @vps.length) do |pager| pager.replace @vps end The view; <%= will_paginate @vps, :previous_label => "prev ", :next_label => " next" -%> renders fine, the number of pages pans out and the page is apparently the first. However, upon: <% @vps.each do |product| %> , the entire sorted array is being

NoMethodError undefined method `link_to_function'

流过昼夜 提交于 2019-12-22 08:15:55
问题 I added ActiveAdmin to my app, updated some gems and now I get a undefined method `link_to_function' when viewing users show page. I have the will_paginate gem and I added a initializer so there's no conflict. kaminari.rb: Kaminari.configure do |config| config.page_method_name = :per_page_kaminari end The error points to the line on from /app/helpers/will_paginate_helper.rb: @template.link_to_function(text.to_s.html_safe, ajax_call, attributes) 回答1: Add a helper method and it will fix your

will paginate miscounting oddness with named scopes

谁说胖子不能爱 提交于 2019-12-22 08:13:27
问题 I recently broke up my query into 4 named scopes to make it easier to re-sort and will paginate which otherwise always worked fine now has problems calculating the number of pages. named_scope :loc, lambda { |id| { :conditions => ['location_id = ?', id ] } } named_scope :datem, lambda { |*args| { :joins => :scannables, :conditions => [ "scannables.bookdate BETWEEN ? and ?", (args[0].to_date || 3.days.from_now), (args[0].to_date+(args[1] || 3)) ], :group => 'scannables.hostel_id', :having =>

How to change will_paginate URLs?

早过忘川 提交于 2019-12-22 04:37:28
问题 I'm trying to change the will_paginate links from the format of /list?page=1 to /list/page/1 . I have the routes setup right for this, but will_paginate is using the query string in links rather than my pretty URL style. How to tell it otherwise? I'm using will_paginate 2.3.16 and Rails 2.3.14 . 回答1: will_paginate uses the url_for helper. If you define routes containing the parameters it uses, it should generate pretty urls. map.connect '/lists/page/:page', :controller => 'lists', :action =>