0
0

More than 3 years have passed since last update.

ページング kaminari ページャ

Posted at
gem
gem 'kaminari','~> 1.2.1'
ターミナル
$  bundle install
$ rails g kaminari:config
$ rails g kaminari:views default
Ostomy/index.html.erb
:
<%= paginate @ostomies %>

ページ数 指定する

.page(params[:page]).reverse_order

app/controllers/〜controller.rb

#デフォルトで件数設定されているので後で変更

def index
  @ostomies= Ostomy.all.page(params[:page]).reverse_order
end

#それか.per(ほしいページ数)    .reverse_order:最新から表示
def index
  @ostomies= Ostomy.all.page(params[:page]).per(7)
end
def index
  @ostomies= Ostomy.all.page(params[:page]).per(7).reverse_order
end

config/initializers/kaminari_config.rb

Kaminari.configure do |config|
  # config.default_per_page = 25  デフォルトでは25件となっているここ変更
  # config.max_per_page = nil
  # config.window = 4
  # config.outer_window = 0
  # config.left = 0
  # config.right = 0
  # config.page_method_name = :page
  # config.param_name = :page
  # config.max_pages = nil
  # config.params_on_first_page = false
end

日本語化する

config/application.rb
config.i18n.default_locale = :ja
config/lacales/ja.yml
ja:
  views:
      pagination:
        first: '最初'
        last: '最後'
        previous: '前ページ'
        next: '次ページ'
        truncate: '〜'
0
0
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
0
0