Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

will_paginate renders blank result

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 ??

like image 408
simo Avatar asked Oct 16 '11 04:10

simo


2 Answers

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.

like image 59
simo Avatar answered Oct 23 '22 06:10

simo


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 %>
like image 41
Alex Grande Avatar answered Oct 23 '22 07:10

Alex Grande