will-paginate

'nil' is not an ActiveModel-compatible object that returns a valid partial path

两盒软妹~` 提交于 2019-12-25 05:25:54
问题 First question, please be gentle :) I am having trouble creating an index view for a client model that belongs_to the user model with a has_many association. The error message: 'nil' is not an ActiveModel-compatible object that returns a valid partial path. Specifically the error refers to the partial on line #11: /views/clients/index.html <% provide(:title, current_user.name) %> <div class="row"> <aside class="span4"> <section> <h1>Your clients</h1> </section> </aside> <div class="span8"> <%

Will_paginate with mongoid (total_entries issue)

跟風遠走 提交于 2019-12-25 02:22:29
问题 When using mongoid with 'will_paginate' gem, it seems like method called 'total_entries' doesnt work which can affect perfomance 回答1: So I was using Mongoid with 'will_paginate' gem and I had this problem with 'total_entries' option, and to be more specific, I dont think it was working at all, which is not very good for perfomance in many situations... After a while I found this gem but it didnt look like 'total_entries' method was working there so here's what I did: 1) Opened mongoid

How implement the Back Link to the page from which comes from

天大地大妈咪最大 提交于 2019-12-25 01:43:06
问题 I have an application with associations and will pagination the pages. The index page from the main object "cat_list" shows links to the association "data_lists". The index page has also pagination with "will_paginate" I show for example page=3 "/cat_lists?page=3" I click the link of a "data_lists" for example "/cat_lists/8984/data_lists" This index page shows a list of data_lists with Edit, Destroy and a New link. And a Back Link to the cat_lists index page now "/cat_lists" What is the best

will_paginate error in production NoMethodError (undefined method `page' for []:ActiveRecord::Relation):

余生长醉 提交于 2019-12-24 14:12:47
问题 I'm using will_paginate gem for ajax-like "see-more" link. It works in development but fails in production. In my production log I get: NoMethodError (undefined method `page' for []:ActiveRecord::Relation): I've tried, in root of production app to type: grep will_paginate Gemfile.lock and get: will_paginate (3.0.4) will_paginate cap bundle:install don't fails installing will_paginate on my VPS, but when I tried to explicitly require 'will_paginate' it steel works in development and fails in

Sort by ranking algorithm using will-paginate

痴心易碎 提交于 2019-12-24 12:17:46
问题 I'm creating a digg-like site using Ruby on Rails that ranks the item (based on this algorithm). I'm using the will-paginate gem list the items in pages. The problem is, will-paginate only allows me to insert ':order =>' based on the table data. I would like to make will-paginate to sort by a number which is calculated using a function based on different fields on the table (e.g number of votes, age hours). How can I do that? 回答1: According to the comments/documentation in the code, you can

Rails 5 : NoMethod Error - Undefined Method Paginate

倖福魔咒の 提交于 2019-12-24 09:51:59
问题 I have a JSON API based on Rails 5. I have a method that brings list of all the products for one particular company, which I want to paginate so that not to bring up all the data at once. For this I came across two gems, namely will_paginate and api-pagination . After running bundle install and restarting the server, I'm still getting the following error : NoMethodError (undefined method `paginate' for #<Api::V1::ProductsController:0x007fb25404db30>) The Products Controller : require 'roo'

Ruby on Rails/will_paginate: Ordering by custom columns

限于喜欢 提交于 2019-12-24 06:45:55
问题 I've got a rather complicated SQL-Query whose results should be paginated and displayed to the user. I don't want to go into details here, but to put it simple I just select all columns of a model, and an additional column , that is used just for sorting purposes. Note.select( ['notes.*', "<rather complicated clause> AS 'x'"] ).joins(...)... After some .join()'s and a .group() , I finally call .order() and .paginate on the relation. If I order by any of the model's natural columns everything

How do I specify custom wording in a will_paginate view helper?

試著忘記壹切 提交于 2019-12-24 03:19:05
问题 I'm using will_paginate 2.3.25 with Rails 2.3.11. I'd like my page_entries_info view helper to say "Displaying all n [my own custom wording]s" instead of auto-generating the item name based on the model. What is the syntax to make it do that? 回答1: Set up your translation yaml file to include what you want to call that model when it is being paginated. After reading this documentation: https://github.com/mislav/will_paginate/wiki/I18n en: will_paginate: models: line_item: zero: line items one:

will_paginate not showing on the Web…

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 02:18:37
问题 The previous question is here : what is the common practice on limit the result in RoR? Here's the users_controller: def show @user = User.find(params[:id]) @posts = @user.posts.paginate :page => params[:page] respond_to do |format| format.html # show.html.erb format.xml { render :xml => @user } end end and my show.html.erb: <%=h @posts.length %> <%=h @posts.inspect %> <%= will_paginate @posts %> But in the browser, I only get this: 4 [#<Post id: 7, title: "I am a root", description: "what

Kaminari is slow with COUNT(*) on a huge table in Postgres [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-24 00:49:06
问题 This question already has answers here : How do I speed up counting rows in a PostgreSQL table? (6 answers) Closed 5 years ago . I'm using the Kaminari gem to paginate a query on a large table (~1.5MM rows). While fetching the actual results pages is quite quick (~20ms), kaminari's added SELECT COUNT(*) WHERE .... is excruciatingly slow, and adds several extra seconds to the execution time. Is there a way to approximate the number of results instead? 回答1: Quick estimate for whole table For a