will_paginate renders blank result
Asked Answered
D

3

5

I have installed the last version of will_paginate, and I am trying to use it at my view like this:

@courses = Course.paginate(:page => params[:page])
will_paginate @courses

but, I get nothing in the view! any idea ??

the following conditions are met:

>> defined? WillPaginate
>> ActiveRecord::Base.respond_to? :paginate

is there something I am missing ??

Doretha answered 16/10, 2011 at 4:8 Comment(0)
D
7

will_paginate will render the links only if items number greater than items per page, in my case, I have only 5 items, also, will_paginate will not render items, it just renders the pagination links.

Doretha answered 17/10, 2011 at 15:55 Comment(1)
Is there a way to force will_paginate to render the links whenever the page parameter is present?Quimper
U
4

You have to render the results, the snippet they showed in the documentation is only for showing the HTML for the breadcrumb. The documentation expected us to know that we still render the object. The only difference is the line in the controller scopes the object to the segmented current page. Hence the :page = url params page.

CONTROLLER:

@courses = Course.paginate(:page => params[:page])

VIEW:

<%= render @courses %>
<%= will_paginate @courses %>
Uninhibited answered 10/11, 2012 at 22:2 Comment(1)
Thanks the <%= render @courses %> was missing in my case!Diuresis
S
0

In the view try this instead:

<%= will_paginate @courses, :param_name => :page %>

This is in the controller of course:

@courses = Course.paginate(:page => params[:page])
Sexy answered 16/10, 2011 at 4:21 Comment(2)
I tried this, but, I still have a blank result I don't know what I am missing here ..Doretha
@Samir: 1- How did you install it? Are you sure it's installed? 2- Your controller is working and returning data? 3- Maybe your controller returns too few records, try to add :per_page => 30 in the paginate parametersExponent

© 2022 - 2024 — McMap. All rights reserved.