Help us understand the problem. What is going on with this article?

kaminariをBootstrap3デザインに適応する

More than 3 years have passed since last update.

環境

  • MacOSX: 10.11.3
  • Rails: 4.2.5
  • Ruby: 2.3.0
  • Kaminari: 0.16.3
  • Bootstrap: 3.3.6

前置き

Kaminariをインストールする手順は結構情報があるので、省略します。

適応方法(本題)

以下のコマンドを実行する。

ターミナル.app
bundle exec rails g kaminari:views bootstrap3

すると、以下のようにviewが生成される。

ターミナル.app
create  app/views/kaminari/_first_page.html.erb
create  app/views/kaminari/_gap.html.erb
create  app/views/kaminari/_last_page.html.erb
create  app/views/kaminari/_next_page.html.erb
create  app/views/kaminari/_page.html.erb
create  app/views/kaminari/_paginator.html.erb
create  app/views/kaminari/_prev_page.html.erb

BootstrapのPaginationを見るとnavタグが入っているので、それに従うのであれば、以下のようにnavタグを追加すればOKです。

app/views/kaminari/_paginator.html.erb
<%= paginator.render do -%>
+    <nav>
      <ul class="pagination">
        <%= first_page_tag unless current_page.first? %>
        <%= prev_page_tag unless current_page.first? %>
        <% each_page do |page| -%>
            <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
                <%= page_tag page %>
            <% elsif !page.was_truncated? -%>
                <%= gap_tag %>
            <% end -%>
        <% end -%>
        <%= next_page_tag unless current_page.last? %>
        <%= last_page_tag unless current_page.last? %>
      </ul>
+    </nav>
<% end -%>

素晴らしい。

スクリーンショット 2016-03-01 10.33.53.png

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away