Module: Comee::Core::Pagination
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController, Common
- Defined in:
- app/controllers/concerns/comee/core/pagination.rb
Instance Method Summary collapse
- #default_per_page ⇒ Object
- #order_by ⇒ Object
- #order_direction ⇒ Object
- #page_no ⇒ Object
- #paginate ⇒ Object
- #paginate_offset ⇒ Object
- #per_page ⇒ Object
Instance Method Details
#default_per_page ⇒ Object
6 7 8 |
# File 'app/controllers/concerns/comee/core/pagination.rb', line 6 def default_per_page 25 end |
#order_by ⇒ Object
22 23 24 |
# File 'app/controllers/concerns/comee/core/pagination.rb', line 22 def order_by params.fetch(:order_by, :id) end |
#order_direction ⇒ Object
26 27 28 |
# File 'app/controllers/concerns/comee/core/pagination.rb', line 26 def order_direction params.fetch(:order_direction, :asc) end |
#page_no ⇒ Object
10 11 12 |
# File 'app/controllers/concerns/comee/core/pagination.rb', line 10 def page_no params[:page]&.to_i || 1 end |
#paginate ⇒ Object
30 31 32 |
# File 'app/controllers/concerns/comee/core/pagination.rb', line 30 def paginate ->(it) { it.limit(per_page).offset(paginate_offset).order("#{order_by}": order_direction) } end |
#paginate_offset ⇒ Object
18 19 20 |
# File 'app/controllers/concerns/comee/core/pagination.rb', line 18 def paginate_offset (page_no - 1) * per_page end |
#per_page ⇒ Object
14 15 16 |
# File 'app/controllers/concerns/comee/core/pagination.rb', line 14 def per_page params[:per_page]&.to_i || default_per_page end |