Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@walkers

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

環境

  • 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 not register and get more from Qiita?
  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
6
Help us understand the problem. What are the problem?