will-paginate

Using will_paginate with multiple models (Rails)

家住魔仙堡 提交于 2019-12-03 18:53:45
问题 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! 回答1

Rails: Showing 10 or 20 or 50 results per page with will_paginate how to?

ⅰ亾dé卋堺 提交于 2019-12-03 13:36:43
问题 me again... I need show 10 or 20 or 50 results number of results per page with a select options in my list of posts using will_paginate plugin Can you help me please? Thanks! 回答1: Looks like the OP also asked here: http://railsforum.com/viewtopic.php?id=33793 and got much better answers. To adapt the best solution there, here's what I like: (in the view) <%= select_tag :per_page, options_for_select([10,20,50], params[:per_page].to_i), :onchange => "if(this.value){window.location='?per_page='

How to render two paginated and ajaxable collections in the same view?

风格不统一 提交于 2019-12-03 12:59:55
问题 In a Rails 3.2 index view I am rendering two partials. <%= render :partial => 'users/user', :locals => {:users => @happy_users} %> <%= render :partial => 'users/user', :locals => {:users => @sad_users} %> and in the partial <% users.each do |user| %> Show some fields <% end %> <%= will_paginate users %> The pagination is not working. If I alter will_paginate to take an instance variable, pagination works (but the wrong collection) <%= will_paginate @users %> How can I pass locals to will

How best to DRY will_paginate options

混江龙づ霸主 提交于 2019-12-03 12:34:05
I have 8 controllers using will_paginate to paginate their index pages. I'd like to override the defaults for "Previous" and "Next" on each without having to specify the same options 8 times. Is there a way to override the defaults only once (perhaps by subclassing will_paginate). will_paginate uses I18n so you can just use that. Given you use English as the default locale the following line should be present in application.rb : config.i18n.default_locale = :en you can then change the text of the pagination links by adding the following to config/locales/will_paginate.en.yml : en: will

Deprecation warning: #apply_finder_options

℡╲_俬逩灬. 提交于 2019-12-03 12:03:33
I get DEPRECATION WARNING: #apply_finder_options is deprecated. when trying this in my user.rb : def User.search(search, page) paginate page: page, per_page: 10, conditions: ['name LIKE ?', "%#{search}%"], order: 'name' end Called through UsersController : def index @users = User.search(params[:search], params[:page]) end The pagination is done with the will_paginate gem. What is triggering the warning and how can I fix it? Been trying some googling, but I find the docs not too comprehensive! I'm pretty sure you just need to pull the order and conditions options out of the paginate method and

will_paginate find out if I'm on the last page

柔情痞子 提交于 2019-12-03 11:51:36
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?? Alexandr Yakubenko @collection.total_pages == @collection.current_page Accessing the @collection.total_pages method will give you the total number of pages currently being returned. You can use this to evaluate against your active page using the @collection

Rails3: How to pass param into custom will_paginate renderer?

我们两清 提交于 2019-12-03 11:13:49
I've got a custom will_paginate renderer that overrides WillPaginate::ViewHelpers::LinkRenderer's link method like so: def link(text, target, attributes = {}) "<a href='/users/95/friends_widget?page=#{target}' rel='next' data-remote='true'>#{text}</a>" end ...and that works great, except you can see the hard-coded 95 in that link. How would I pass a parameter (e.g. user or user's ID) into the custom renderer via the Rails view? <%= will_paginate(@user_friends, :remote => true, :renderer => FriendsRenderer) %> Or is there something I'm missing, some easier way to do it? BTW: @user_friends isn't

How to customize the will_paginate link base?

蓝咒 提交于 2019-12-03 09:08:49
<%= 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! 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] = 'MyLinkRenderer' in application_helper.rb class MyLinkRenderer < WillPaginate::LinkRenderer def page_link(page,

will_paginate JSON support?

左心房为你撑大大i 提交于 2019-12-03 05:54:47
问题 I wonder if anyone could please tell me if will_paginate can support JSON out of the box or if this has to be hacked? I would like to add page data to the JSON responses while will_paginate manages pagination. 回答1: Something in the lines of: @posts = Post.paginate :page => params[:page] respond_to do |format| format.json { render :json => { :current_page => @posts.current_page, :per_page => @posts.per_page, :total_entries => @posts.total_entries, :entries => @posts } } end Once you figure out

Using will_paginate without :total_entries to improve a lengthy query

喜你入骨 提交于 2019-12-03 00:40:08
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 previous link? This would only occur of course if records existing prior to the ones displayed in the