will-paginate

will_paginate JSON support?

♀尐吖头ヾ 提交于 2019-12-02 20:34:23
I wonder if anyone could please tell me if will_paginate can support JSON out of the box or if this has to be hacked? I would like to add page data to the JSON responses while will_paginate manages pagination. Something in the lines of: @posts = Post.paginate :page => params[:page] respond_to do |format| format.json { render :json => { :current_page => @posts.current_page, :per_page => @posts.per_page, :total_entries => @posts.total_entries, :entries => @posts } } end Once you figure out what format you want, you can always define a to_json method on a WillPaginate::Collection. Adding

Rails - will_paginate says “variable appears to be empty. Did you forget to pass the collection object for will_paginate?”

半世苍凉 提交于 2019-12-02 04:07:52
I have this query: @cars = Car.paginate(page: params[:page], per_page: 5).order(created_at: :desc).group_by { |r| r.created_at.to_date } and in the view: = will_paginate @cars But I am getting this error (rendered in site#index ): The @site variable appears to be empty. Did you forget to pass the collection object for will_paginate? I've also tried to update the query this way: @cars = Car.order(created_at: :desc).paginate(page: params[:page], per_page: 5).group_by { |r| r.created_at.to_date } But the error is still the same. How to fix this issue? Thank you You can do something like this in

undefined method `will_paginate', Rails 3.1 / DataMapper

一个人想着一个人 提交于 2019-12-02 00:03:41
Newly installed will_paginate 3.0.0 gem 'will_paginate', '~> 3.0.0', :require=>'will_paginate/data_mapper' Running a controller query: @tickets = Ticket.paginate(:page => params[:page], :per_page => 5,:username => @ticket.username) Which works, pulls up all the tickets for a user and paginates in 5's if I put ?page=X where x is a page number in the url. =will_paginate(@tickets) in the view does not work, this results in undefined method `will_paginate' for #<#<Class:0x000000053674c8>:0x0000000535cd48> So will_paginate works, but not the view helper. Am I missing something? I'm using slim

Why do I get “undefined method 'paginate'” error in production?

烂漫一生 提交于 2019-12-01 20:53:33
问题 I get this error when using will_paginate on production server: I, [2013-10-24T20:17:40.386696 #18564] INFO -- : Started GET "/meals" for 190.273.432.55 at 2013-10-24 20:17:40 +0000 I, [2013-10-24T20:17:40.388972 #18564] INFO -- : Processing by MealsController#index as HTML I, [2013-10-24T20:17:40.395022 #18564] INFO -- : Completed 500 Internal Server Error in 6ms F, [2013-10-24T20:17:40.396720 #18564] FATAL -- : NoMethodError (undefined method `paginate' for #<ActiveRecord::Relation:

get will_paginate to define a custom offset on the first page

前提是你 提交于 2019-12-01 17:15:51
i'm building a news section on my rails website and it uses will_paginate for pagination. now i was wondering how i can specify a custom offset for the first page with will_paginate. something like this: @featured_news = Post.first @news = Post.offset(1).paginate(:page => params[:page]) i need the latest news-entry to be special and not be included in the @news objects. how i can achieve this? thanks for your time! MrRuru will_paginate redefines every offset and limit query conditions, to get the rows of a specific page. I can see two options for you : The ugly one : take advantage of the fact

will_paginate can it order by day

落花浮王杯 提交于 2019-12-01 12:47:07
问题 SCENARIO: I have a Pictures table that contains hundreds of photos. I'm currently using 'will_paginate' to paginate 100 photos per page. I would like to continue using 'will_paginate' BUT I want the pagination to be driven by the day. I have tried the following by using sort_by but I don't think it's working. @pics = Picture.paginate(:page => params[:page]).sort_by(&:created_at) END GOAL: Home page shows me today's pictures only. Now if I click on page 2 it shows me yesterdays pictures only.

How to use will_paginate with a nested resource in Rails?

依然范特西╮ 提交于 2019-12-01 08:43:26
I'm new to Rails, and I'm having major trouble getting will_paginate to work with a nested resource. I have two models, Statement and Invoice. will_paginate is working on Statement, but I can't get it to work on Invoice. I know I'd doing something silly, but I can't figure it out and the examples I've found on google won't work for me. statement.rb class Statement < ActiveRecord::Base has_many :invoices def self.search(search, page) paginate :per_page => 19, :page => page, :conditions => ['company like ?', "%#{search}%"], :order => 'date_due DESC, company, supplier' end end statements

How to use will_paginate with a nested resource in Rails?

﹥>﹥吖頭↗ 提交于 2019-12-01 06:28:12
问题 I'm new to Rails, and I'm having major trouble getting will_paginate to work with a nested resource. I have two models, Statement and Invoice. will_paginate is working on Statement, but I can't get it to work on Invoice. I know I'd doing something silly, but I can't figure it out and the examples I've found on google won't work for me. statement.rb class Statement < ActiveRecord::Base has_many :invoices def self.search(search, page) paginate :per_page => 19, :page => page, :conditions => [

Item's page and will_paginate

余生颓废 提交于 2019-12-01 04:12:15
I have some photos that are split on successive pages through will_paginate plugin. When you open a photo and then return to all photos using a link, you always return to the first page (e.g. the photo is displayed on page 5, you open the photo, click a link to show all photos and expect that you are on page 5 again, but you are on page 1). Now, is there any method to get the page number to which a photo belongs to? I tried to pass a GET parameter, but this only works if the user doesn't perform any more actions (e.g. post a comment, edit photo, ecc.). Simone Carletti page = (number_of_records

Infinite scroll and will_paginate appending the 'next page' of items multiple times

萝らか妹 提交于 2019-11-30 21:30:12
I am following this railscast in trying to implement an infinite scroll page on my rails app. When a user scrolls down to the bottom of the page an new set of items is appended and the page extends, however it is appended to the page multiple times and the event triggers again on scrolldown even when all the items in the array have been loaded, appending the same set of items again multiple times. What I would like is to append the 'next page' of items each time a user scrolls to the bottom, and subsequent next pages as the user scrolls to the bottom again. Here is the jQuery for this function