will-paginate

Using will_paginate with multiple models (Rails)

扶醉桌前 提交于 2019-11-30 02:25:36
Pretty sure that I'm missing something really simple here: I'm trying to display a series of pages that contain instances of two different models - Profiles and Groups. I need them ordering by their name attribute. I could select all of the instances for each model, then sort and paginate them, but this feels sloppy and inefficient. I'm using mislav-will_paginate, and was wondering if there is any better way of achieving this? Something like: [Profile, Group].paginate(...) would be ideal! Good question, I ran into the same problem a couple of times. Each time, I ended it up by writing my own

will_paginate with endless Scrolling | Rails4

安稳与你 提交于 2019-11-29 23:13:21
THIS IS THE SOLUTION So i'm using will_paginate / Bootstrap Will Paginate with Endless Scrolling. To get the Pagination working: 1.) In my Controller i updated my index action with @clips = Clip.order("created_at desc").page(params[:page]).per_page(20) 2.) Edit my index view: <%= will_paginate @clips%> DONE Pagination works just fine. To Add Endless scrolling i did the same steps as in my previous Rails 3 App. 1.) Edit my clips.js.coffee jQuery -> $('#clips-masonry').imagesLoaded -> $('#clips-masonry').masonry itemSelector: ".clips-masonry" # Thats my Masonry if $('.pagination').length # Thats

Combine arrays of conditions in Rails

懵懂的女人 提交于 2019-11-29 02:44:46
I'm using the Rails3 beta, will_paginate gem, and the geokit gem & plugin. As the geokit-rails plugin, doesn't seem to support Rails3 scopes (including the :origin symbol is the issue), I need to use the .find syntax. In lieu of scopes, I need to combine two sets of criteria in array format: I have a default condition: conditions = ["invoices.cancelled = ? AND invoices.paid = ?", false, false] I may need to add one of the following conditions to the default condition, depending on a UI selection: #aged 0 lambda {["created_at IS NULL OR created_at < ?", Date.today + 30.days]} #aged 30 lambda {[

Will_paginate Plugin on two objects on same page

爷,独闯天下 提交于 2019-11-29 02:34:52
问题 Hello I am using will_paginte plugin on two objects on a same page. Like on stackoverflow. There is a profile page on which there is a pagination on two things QUestions and answers. I am having problem ie:-- when user is clicking on questions pagination page 2. answers page are also updating. The reason is both is sending a post variable ie params[:page] How to change this variable so that only one should be updated. and how to maintain that user should not lose the other page. ie he is on

How to Implement ajax pagination with will_paginate gem

我是研究僧i 提交于 2019-11-27 11:08:47
I am using will_paginate gem in my ROR project to show the records in pages. I want the next page to be loaded without reloading the whole page using ajax . I found some examples on the net but they don't work for me. How to do this? Pierre Pretorius Create a new helper (ex. app/helpers/will_paginate_helper.rb) with the following content: module WillPaginateHelper class WillPaginateJSLinkRenderer < WillPaginate::ActionView::LinkRenderer def prepare(collection, options, template) options[:params] ||= {} options[:params]['_'] = nil super(collection, options, template) end protected def link(text

Overriding a module method from a gem in Rails

蹲街弑〆低调 提交于 2019-11-27 10:55:59
The will_paginate gem is broken on my version of Oracle. The default paginate_by_sql method in the WillPaginate module is inserting an extra 'AS' into a query and causing it to fail. The code itself is easily fixed, but I'm not sure of the best way to get Rails to pick up my change. I don't want to change the code in the gem itself, as that will leave my code broken on other machines. I tried creating an lib/test.rb file containing: module WillPaginate def paginate_by_sql (my code goes here) end end and requiring it from environment.rb, but it's not picking up my changes. I also tried

Overriding a module method from a gem in Rails

蹲街弑〆低调 提交于 2019-11-26 17:58:38
问题 The will_paginate gem is broken on my version of Oracle. The default paginate_by_sql method in the WillPaginate module is inserting an extra 'AS' into a query and causing it to fail. The code itself is easily fixed, but I'm not sure of the best way to get Rails to pick up my change. I don't want to change the code in the gem itself, as that will leave my code broken on other machines. I tried creating an lib/test.rb file containing: module WillPaginate def paginate_by_sql (my code goes here)

How to Implement ajax pagination with will_paginate gem

霸气de小男生 提交于 2019-11-26 15:26:20
问题 I am using will_paginate gem in my ROR project to show the records in pages. I want the next page to be loaded without reloading the whole page using ajax . I found some examples on the net but they don't work for me. How to do this? 回答1: Create a new helper (ex. app/helpers/will_paginate_helper.rb) with the following content: module WillPaginateHelper class WillPaginateJSLinkRenderer < WillPaginate::ActionView::LinkRenderer def prepare(collection, options, template) options[:params] ||= {}

Ruby on Rails will_paginate an array

ⅰ亾dé卋堺 提交于 2019-11-26 11:11:49
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 keithepley will_paginate 3.0 is designed to take advantage of the new ActiveRecord::Relation in Rails 3, so it defines paginate only on relations by default. It can still work

Paginating an Array in Ruby with will_paginate

我是研究僧i 提交于 2019-11-26 07:33:27
问题 I have an array @level1 which looks like this : [[3.0, 4, 2], [2.0, 48, 3], [2.1, 56, 4], ............] I want to apply pagination on this array such each page displays only a few rows at once. I tried this: @temp1 = @level1.paginate(:page => params[:page]) But it throws the following error: undefined method `paginate\' for [[3.0, 4, 2], [2.0, 48, 3], [2.1, 56, 4]]:Array How can I perform pagination on this using will_paginate? 回答1: Sure, you can use WillPaginate::Collection to construct