will-paginate

Rails 5 using will_paginate to create a load more button

試著忘記壹切 提交于 2020-08-01 05:13:06
问题 So I'm trying to create a load more button (not infinite scroll although some simple js tweaks could make it so). I'm using the will_paginate gem in Rails 5. Its currently all working as expected except when I click load more it loads the next page posts twice e.g: Load more > Post 4, Post 5, Post 6, Post 4, Post 5, Post 6 FYI my 'posts' are @links: links_controller.erb def index @links = Link.order('created_at DESC').paginate(:page => params[:page], :per_page => 3) respond_to do |format|

will_paginate and .sort =>

蓝咒 提交于 2020-01-25 05:36:49
问题 I recently got the will_paginate gem installed and it works great, but I would like it to work with the setup I currently have. Right now I show all feeds (or posts) on the same page, but they are sorted after how many people clicked on that page: controller.rb @t = Time.now @h1 = @t - 1.hour @feeds = Feed.find(:all, :order => "created_at DESC").sort { |p1, p2| p2.impressionist_count(:filter=>:all, :start_date=>@h1) <=> p1.impressionist_count(:filter=>:all, :start_date=>@h1)} Now... I tested

Combine two ActiveRecord::Relation with OR, not AND, returning a Relation and not an Array to be able to paginate later

家住魔仙堡 提交于 2020-01-14 12:46:51
问题 a and b are ActiveRecord::Relation objects which return the same type of objects(Micropost objects in this case) a.class => ActiveRecord::Relation b.class => ActiveRecord::Relation a.first => Micropost(...) b.first => Micropost(...) #They both return the same type of objects c=a+b c.class => Array #This is not what i'm looking for c=a|b c.class => Array #Not what i'm looking for either c=(a or b) c.class => ActiveRecord::Relation #But it is just a, so it's wrong c==a => true a.merge(b) => []

Rails: Prevent will_paginate from calling #count of ActiveRelation

不羁岁月 提交于 2020-01-14 07:59:12
问题 When I pass will_paginate an ActiveRelation, it always calls its #count method and hits the database to find out the total number of items. But this operation takes time and I have the total number already cached and ready. Can I pass this pre-calculated count to will_paginate and stop it from hitting the database? I tried the :count option, but it is passed to ActiveRecord as an option: active_relation.paginate(page: 2, per_page: 100, count: total_count) Thanks! :) 回答1: Passing the cached

Will ajax will pagination is rendergin the page twice

痴心易碎 提交于 2020-01-14 06:06:09
问题 I am using ajax will pagination in my rails application. The pagination is working perfectly. But in one page when I click on next page link. It showing the page twice. But in other pages it working fine. Here is my index.js.erb: $('.sort_paginate_ajax').html("<%= escape_javascript(render("jobs"))%>"); $(".tablesorter").tablesorter(); And my index.html.erb is like: <div class="sort_paginate_ajax"><%= render 'jobs' %></div> The server log is: Started GET "/jobs?page=2&_=1400322005679" for 127

:entry_name does not change for will_paginate; not working?

◇◆丶佛笑我妖孽 提交于 2020-01-07 02:16:11
问题 Does anyone know why the entry name isn't changing to what I want? <div class="digg_pagination"> <div class="page_info"> <%= page_entries_info @user_prices, :entry_name => 'Price', :plural_name => 'Prices' %> </div> <%= will_paginate @user_prices, :container => false %> </div> I already tried getting rid of the :plural_name option but that didn't work either. What could be the problem? 回答1: At some point the :entry_name option in page_entries_info has changed to :model . So you can now do (in

How to make a path to a paginated url?

北战南征 提交于 2020-01-06 13:04:33
问题 When user #1 likes/comments on user #2, user #2 gets a notification: notifications/_notifications.html.erb <%= link_to "", notification_path(notification.id), method: :delete, class: "glyphicon glyphicon-remove" %> <%= link_to Comment.find_by(notification.comment_id).user.name, user_path(Comment.find_by(notification.comment_id).user.id) %> commented on <%= link_to "your activity", (notification.activity_id) %> but upon user #2 clicking the notification it doesn't lead anywhere since I removed