简体   繁体   中英

in rails using will_paginate and partials

I have a collection of people that is paginated with will_paginate

@people = Person.paginate :page => params[:page],
                :limit => 10,
                    :conditions =>   ['company_id = ? ' , @company.id ] 

The people are shown on the company/view page and rendered with a partial. Note that the partial is in the views of 'people'

<%= render :partial => "people/person" , :locals => { :people => @people }%>

in the partial ...

<% for person in @people %>

     ...

<%end%>

<%= will_paginate @people %>

Now the partial does work, it renders all of the people and shows the paginate links on the bottom. However it doesn't not actually paginate the collection and instead it shows everything on the first page.

I am clearly missing something rather basic.

Thanks in advance.

你错过了per_page吗?

Per_page should be the problem.

Also make :page => params[:page] look like :page => params[:page] || 1 :page => params[:page] || 1 so that will_paginate will stop complaining on blank page parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM