LoginSignup
5
6

More than 5 years have passed since last update.

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

Posted at

環境

  • 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

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6