will-paginate

How to change will_paginate URLs?

一曲冷凌霜 提交于 2019-12-05 05:16:09
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 . 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 => 'index' Please make sure, you define this route above any routes that could also match your controller

Undefined method `paginate'

好久不见. 提交于 2019-12-05 02:05:29
I'm trying to use the will_paginate gem but something's wrong. I'm stuck with an undefined method `paginate' error. I read many issues and try a lot of things. Here's what I've got : This is my LocationsController.rb: def index @locations = Location.all respond_to do |format| @locations = @locations.paginate(:page => params[:page], :per_page => 10) format.html #index.html.erb format.json { render json: @locations } end end And this is my will_paginate's line in my index.html.erb : <%= will_paginate @locations %> And this is the error: undefined method `paginate' for #<Class:0xaa2e48c> I also

How to paginate sunspot in this manner?

陌路散爱 提交于 2019-12-04 17:39:58
I have the following model associations: class Product < ActiveRecord::Base has_many :prices class Price < ActiveRecord::Base belongs_to :product Here is my controller class SearchController < ApplicationController # Using Sunspot here. def index @search = Product.search do fulltext params[:search] paginate(:per_page => 5, :page => params[:page]) end @products = @search.results end end and then my view: <%= will_paginate @products %> <% @products.each do |product| %> <%= product.name %> <% prices.each do |price| %> <%= price.price %> <% end %> <% end %> Lets say I have 10 Products that each

will_paginate find out if I'm on the last page

谁说我不能喝 提交于 2019-12-04 16:49:10
问题 I'm trying to use will paginate with ajax, but I don't show the will_paginate buttons... instead I use a see more button, that makes an Ajax request and append the results to the page. what I'm trying to do is disable this see more button if I hit the last page of records!! Any idea how to know that the current page is the last page?? 回答1: @collection.total_pages == @collection.current_page 回答2: Accessing the @collection.total_pages method will give you the total number of pages currently

Rails3/will_paginate/Ajax - next/previous link doesn't work properly (is it a bug?)

守給你的承諾、 提交于 2019-12-04 16:48:48
I am following the " Pagination with ajax " railscast for my rails 3 application. Everything seems to work great, except the fact that Previous and next links don't work at all. Basically, It appears that the previous link is stuck even if I click on other pages, (when I am on the user/show page1) The "next link" works one time till the page 2 (I can't use it after) Numbers didn't update when I come to "..." I would be pleased to know if someone experience the same problem (a bug?) or if my code is wrong. I use will paginate ("~> 3.0.pre2"and jquery 1.8.10) for a list of microposts dependent

Endless page with will_paginate not working with partial

笑着哭i 提交于 2019-12-04 15:51:24
I've been following the railscast on endless page and had previously done the same for will_paginate, but I'm getting errors however I try to implement it in my specific situation. The will_paginate gems works perfectly, as does the jQuery call to the dom as far as I can tell from reading the developer tools in Chrome. The issue is with what is being returned - rails doesn't like it. Here's some code: In videos.js.coffee : jQuery -> if $('.pagination').length $(window).scroll -> url = $('.pagination .next_page').attr('href') if url && $(window).scrollTop() > $(document).height() - $(window)

How to customize the will_paginate link base?

随声附和 提交于 2019-12-04 13:42:38
问题 <%= will_paginate(@posts) %> # will generate the links like this '<a href="/posts?page=n">a link</a>' What should I do if I want to change the href base on /contents , etc. <a href="/contents?page=n">a link</a> ? It seems that there is no options for this , help! 回答1: You will probably have to write your own LinkRenderer. See this blog post, and the code for LinkRenderer. Briefly: in environment.rb you need something like this: WillPaginate::ViewHelpers.pagination_options[:renderer] =

will_paginate with named_scopes

杀马特。学长 韩版系。学妹 提交于 2019-12-04 08:12:53
问题 I'm using will_paginate for pagination, which has been working well so far, except for this one thing. If I try to paginate a scope, for instance class User < ActiveRecord::Base named_scope :scope, lambda { etc } end User.scope.paginate({:page => params[:page], :per_page => 10}) That will tell me paginate is an undefined method. I'd rather not have to use a second solution for only this scope, is there something I can do here? 回答1: Lowgain, klew's version should work out of the box. In your

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

浪尽此生 提交于 2019-12-04 04:59:34
问题 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

rails pagination - different per_page value page 1 from subsequent pages

旧时模样 提交于 2019-12-03 22:33:11
I have kinda blog/wiki application where I'd like the home page to include a welcome/landing message and the 5 most recent blog entries and pagination linking to older entries. Is it possible to have, for example, 5 pages returned as page one of paginated search results and 15 for subsequent pages? I'm currently using will_paginate. jrichardlai You can use WillPaginate::Collection , here is an example you can use for this : def self.find_with_pagination(params = {}) WillPaginate::Collection.create(params[:page].to_i < 1 ? 1 : params[:page], per_page_for_page(params[:page])) do |pager| # inject