Jbur43
Jbur43

Reputation: 1312

Kaminari pagination not showing on second, third page

I am using Kaminari to add pagination to my app, but when I click "next" to go to the second page, I do not see the next set of content.

My view looks like this

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

My URL on the first page where the data is displaying is http://localhost:3000/guestbooks/new

The data is not displaying on http://localhost:3000/guestbooks/new?page=2

and I cannot determine why.

Here is my controller

class GuestbooksController < ApplicationController
    def index
        @guestbooks = Guestbook.all.limit(5).page(params[:page])
    end

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

    def create
        @guestbook = Guestbook.new(guestbook_params)
        # @guestbooks = Guestbook.all.limit(1).page(params[:page])

        if @guestbook.save
            flash.now[:notice] = "Thanks for taking the time to write us! We greatly appreciate it!"
            render :new
        else
            flash.now[:notice] = "Your message failed to post, please try again"
            render :new
        end
    end

    private
    def guestbook_params
        params.require(:guestbook).permit(:name, :email, :message)
    end
end

Upvotes: 1

Views: 1375

Answers (1)

Pardeep Dhingra
Pardeep Dhingra

Reputation: 3946

We dont need to limit or paginate while fetching if we are doing same thing again by kaminari

Try this:

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

Upvotes: 2

Related Questions