will-paginate

Tire search and will_paginate - undefined method `offset'

浪子不回头ぞ 提交于 2020-01-05 07:45:06
问题 After headaches with ThinkingSphinx and Solr/Sunspot, we're trying out ElasticSearch and Tire as our search back-end - but I've hit a problem. Here's my search command in the controller: @results = Item.search params[:search], :page => ( params[:page] || 1 ), :per_page => 20 And this is the problem section of the view: <%= page_entries_info @results %> The error message I'm getting is undefined method `offset' for #<Tire::Results::Collection:0xa3f01b0> but only when there is more than one

Problem with named_scope causes error in will_paginate - how to include group_by in count?

与世无争的帅哥 提交于 2020-01-04 08:27:11
问题 [rails 2.3.12] named_scope: named_scope :order_by_price, lambda {{:joins => :variants, :group => "products.id", :order => "MAX(price)"}} console: 1. > Product.order_by_price.size => 21 2. > p = Product.order_by_price > p.size => 4 sql queries: 1. SELECT count(*) AS count_all FROM `products` INNER JOIN `variants` ON variants.product_id = products.id 2. SELECT `products`.* FROM `products` INNER JOIN `variants` ON variants.product_id = products.id GROUP BY products.id ORDER BY MAX(price) I use

Will_paginate for includes comments

爱⌒轻易说出口 提交于 2020-01-03 03:01:20
问题 I'm discovering the gem will_paginate which is great ! But I'm facing a problem of using. I'm building a group>post>comments app, so in my group show page i'm displaying posts and their comments. To limit the numbers of queries, i'm using includes method like this : Group_controller : def show @posts = @group.posts.order(upd_at: :desc).includes(:user).includes(comments: :user).paginate(page: params[:page], per_page: 10) end So I would like to also paginate my comments. Do you know a way to do

Will_paginate for includes comments

╄→尐↘猪︶ㄣ 提交于 2020-01-03 03:01:07
问题 I'm discovering the gem will_paginate which is great ! But I'm facing a problem of using. I'm building a group>post>comments app, so in my group show page i'm displaying posts and their comments. To limit the numbers of queries, i'm using includes method like this : Group_controller : def show @posts = @group.posts.order(upd_at: :desc).includes(:user).includes(comments: :user).paginate(page: params[:page], per_page: 10) end So I would like to also paginate my comments. Do you know a way to do

Rails 3 and will_paginate - elegant way, how to get total_pages

ぃ、小莉子 提交于 2020-01-02 02:01:48
问题 I am working with will_paginate plugin in Rails 3 and I am trying to get to some variable the count of pages (total_pages). I thought the total pages is in globally variable @total_pages , or in @option[:total_pages]**, but if I will use this variables in my view, so it don't work. I know, I can get the total pages of my items in DB table separately by this plugin, but couldn't be so elegant, if I will have that value already stored in some variable by plugin... So I would like to ask you -

Using will_paginate without :total_entries to improve a lengthy query

99封情书 提交于 2019-12-31 18:32:41
问题 I have a current implementation of will_paginate that uses the paginate_by_sql method to build the collection to be paginated. We have a custom query for total_entries that's very complicated and puts a large load on our DB. Therefore we would like to cut total_entries from the pagination altogether. In other words, instead of the typical pagination display of 'previous 1 [2] 3 4 5 next', we would simply like a 'next - previous' button only. But we need to know a few things. Do we display the

Rails will_paginate custom route

隐身守侯 提交于 2019-12-30 03:16:15
问题 How can I use will_paginate with a custom route? I have the following in my routes: map.connect 'human-readable/:name', :controller => :tags, :action => 'show' but will_paginate uses url_for as far as I can tell, but I want to use 'human-readable' instead of url_for, but how? Edit When I click the paging link generated by will_paginate , it's using: "tags/show?name=Elektronikindustri&page=1" Instead of: "/human-readable/show?name=Elektronikindustri&page=1" I want will_paginate to use my

Rails: Using will_paginate with a complex association find

泄露秘密 提交于 2019-12-30 02:27:27
问题 I'm encountering a problem with will_paginate while doing a complex find. :photo has_many :tags, :through => :tagships :item has_many :photos :photo belongs_to :item @photos = @item.photos.paginate :page => params[:page], :per_page => 200, :conditions => [ 'tags.id IN (?)', tag_ids], :order => 'created_at DESC', :joins => :tags, :group => "photos.id HAVING COUNT(DISTINCT tags.id) = #{tag_count}" I want to fetch all the photos who have all the tags in the tag_ids array. MySQL's IN usually does

Ruby on Rails will_paginate an array

冷暖自知 提交于 2019-12-27 10:33:22
问题 I was wondering if someone could explain how to use will_paginate on an array of objects? For example, on my site I have an opinion section where users can rate the opinions. Here's a method I wrote to gather the users who have rated the opinion: def agree_list list = OpinionRating.find_all_by_opinion_id(params[:id]) @agree_list = [] list.each do |r| user = Profile.find(r.profile_id) @agree_list << user end end Thank you 回答1: will_paginate 3.0 is designed to take advantage of the new

Using will_paginate while applying a scope with params to the Model

亡梦爱人 提交于 2019-12-25 07:14:10
问题 I am attempting to create a search box that can be used to search User's by their name. The problem I am running into is that I also want to use the will_paginate gem. This line of code @users = User.name(params[:name]).paginate(page: params[:page]) if params[:name].present? is where I think the problem lies. class UsersController < ApplicationController def index @users = User.all.paginate(page: params[:page]) @users = User.name(params[:name]).paginate(page: params[:page]) if params[:name]