Home>
I'm thinking of customizing pagination using kaminari in Ruby on Rails.
The current pagenation is below.
The customization I want to do will be displayed on 5 pages as shown below.
(Previous) (1) (2) (③) (4) ・ (10) (Next)
(Previous) (1) ・ (3) (④) (5) ・ (10) (Next)
* ○ is the display page.
If i have a solution here, I would appreciate it if you could teach me.
If i have any necessary files, please let us know.
Thank you.
<ul>
<li><% = paginate @admins%></li>
</ul>
def news
@admins = Admin.order ("created_at DESC"). page (params [: page]). per (1)
end
ja:
time: time:
formats: formats:
default: "% Y% m month% d day"
views:
pagination:
previous: "previous"
next: "Next"
truncate: "・"
#frozen_string_literal: true
Kaminari.configure do | config |
config.default_per_page = 8
config.max_per_page = nil
# config.window = 3
# 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
<% = paginator.render do%>
<nav role = "navigation" aria-label = "pager">
<% = prev_page_tag%>
<% each_page do | page |%>
<% if page.display_tag?%>
<% = page_tag page%>
<% elsif! page.was_truncated?%>
<% = gap_tag%>
<% end%>
<% end%>
<% unless current_page.out_of_range?%>
<% = next_page_tag%>
<% end%>
</nav>
<% end%>
What I tried
I tried to touch views and config with reference to the article, but there was no change.
-
Answer # 1
-
Answer # 2
The settings here are still commented out, what happens if I comment them out?
#frozen_string_literal: true Kaminari.configure do | config | config.default_per_page = 8 config.max_per_page = nil config.window = 3 # Comment out here config.outer_window = 1 # Comment out here # 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
Related articles
- ruby on rails 6 - about validation (number of characters) of rails tweet posting
- ruby on rails - rails render: about the matter that the url after new is different
- i want to move to the second page about the pagination function of laravel
- about description of manifest file of ruby on rails
- ruby - about accelerating heroku's rails app
- ruby on rails 5 - about lint/syntax error of rubocop
- ruby - about the problem of duplicate devise error messages (allow_blank: ture doesn't work!)
- ruby - about the error content displayed in "rails" rspec
- ruby on rails - about image posting page argumenterror
- ruby - [rails] about partial templates
- ruby on rails - about multi-word search to multiple columns using ransack
- [ruby on rails] about header setting using bootstrap
- ruby on rails - about screen transition from rails top page to calendar page
- ruby on rails 6 - about rails error "wrong number of arguments (given 1, expected 0)"
- ruby on rails - about rails create action
- ruby - about record duplication
- ruby on rails - about nomethoderror in skilscontroller # create
- about ruby exception method stackrace
- ruby - about rails controller new action
Related questions
- ruby - about rails controller new action
- ruby - data including rails hyphen becomes # and is not displayed
- ruby - about viewport introduction
- ruby - n + 1 problem in api mode
- ruby - about rails routing
- ruby - link_to method:: post doesn't work
- ruby - rails6 active_strage cannot be installed
- ruby - unable to create table with foreign key
- ruby - how to pass the "password" on the wizard screen
There is, but I think that it is better to get into the habit of seeing the formula as much as possible.
It looks like the following in the default state without using a template.
After that, I think that I should arrange the layout, translate it into Japanese, and delete First and Last.
* I couldn't find a way to delete first and last, but if you're not particular about it, you may delete it with css.
P.S.
When the first page is displayed, it will look like the one below, so it seems necessary to take some measures such as making a conditional branch and calling the one with the outer increment or decrement.
It is a further addition.
Premise: With gem installed (kaminari config is not set, paginator is not customized)
With the code belowAlmostIt can be realized. (Actually, it is better to write else properly)
https://kaminari-test.herokuapp.com/
AlmostBecause when you display page 4,
Prev 1 2 3 4 5 ... 25 Next
It will be. (* Same for page 22)If you skip two or more characters, it will be ..., but if you skip one character, it will not be ... It seems to be the specification of kaminari.