-1

I wanted to add some pagination to my rails project. I've already added Kaminari and I've managed to display only 10 records per page. But I'm already missing the next/prev arrow and the page indicator.

I'm using Kaminari.paginate_array(@array).page(params[:page]).per(10)

This is the only thing I've added until now.

I don't know if it's important, but in my view I have @array.to_json

What should I add to display the arrows?

View code:

<% content_for :create_button do %>
  <%= create_button(new_battery_reset_path) %>
<% end %>
<div class="tab-content">
  <%= paginate @battery_resets %>
  <div class="tab-pane active" id="battery-resets" role="tabpanel"
    data-battery-resets='<%= @battery_resets.to_json %>'>
  </div>
  <div class="tab-pane" id="profile" role="tabpanel">...</div>
  <div class="tab-pane" id="messages" role="tabpanel">...</div>
</div>

controller code:

def index
    @battery_resets = Kaminari.paginate_array(BatteryResetDecorator.build_collection(
      ::Filters::BatteryReset.new(
          current_account.battery_resets.includes({ device: :account },
            :device_inspection)
      ).apply(permited_params[:q])
    )).page(params[:page]).per(10)

    respond_with(@battery_resets)
  end

enter image description here

Richard Peck
  • 76,116
  • 9
  • 93
  • 147

2 Answers2

1

You might want to put <%= paginate @array %> in your rails view. Also try to read gem's wiki first before asking any questions.( kaminari wiki )

Tushar Maroo
  • 325
  • 1
  • 5
  • 24
0

Per the docs:

Just call the paginate helper:

<%= paginate @battery_resets %>

This will render several ?page=N pagination links surrounded by an HTML5 <nav> tag.

This is the same pattern for will_paginate (another gem) also.

--

In regards your fa_icon error, that's caused by the font-awesome-rails gem; it means the helper is not available.

The way to fix it is to make sure you're only using the bundled files with Kaminari. If you've changed _next_page.html.erb in any way, the error is likely coming back now.

--

The quick fix for the fa_icon error is to add font-awesome-rails to your Gemfile:

#Gemfile
gem "font-awesome-rails"
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Richard Peck
  • 76,116
  • 9
  • 93
  • 147