Jbur43
Jbur43

Reputation: 1312

Paginate with Kaminari not working

I am trying to use basic Kaminari to do some pagination, but I am having trouble getting it to work properly.

I have installed the Kaminari gem and then in my controller I have the following code:

def new
    @guestbook = Guestbook.new
    @guestbooks = Guestbook.all.limit(5).page(params[:page])
end

In my associated new view I have this code...

<%= paginate @guestbooks %>

<div class="span1">
    <% @guestbooks.each do |g| %>
        <br/>
        <h4><%= g.name %>, <%= g.created_at %><br/></h4>
        <%= g.message %><br/>......

However when I reload my page I do not see any pagination.

Upvotes: 1

Views: 5253

Answers (2)

Atchyut Nagabhairava
Atchyut Nagabhairava

Reputation: 1413

I completely support @Yang answer, and also I would suggest to make sure you have given min number of entries which is greater than the per page value.

for example:

def index
@posts = Post.page(params[:page]).per(10)
end

In this case: you must be created more than ten entries to get the pagination.

Upvotes: 3

Yang
Yang

Reputation: 1923

You need to use this in your controller:

@guestbooks = Guestbook.all
@guestbooks = Kaminari.paginate_array(@guestbooks).page(params[:page]).per(5)

And add this in your view:

<%=paginate @guestbooks%>

Upvotes: 4

Related Questions