Skip to content

Commit

Permalink
pagination, sort (fs#20)
Browse files Browse the repository at this point in the history
* pagination, sort

* pagination, sort 2

* pagination, sort 3

* pagination, sort 4

---------

Co-authored-by: Denis Zakharov <[email protected]>
  • Loading branch information
stepantishhen and DenisZackharov authored Oct 3, 2023
1 parent 0642c1c commit ac65df6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@
/yarn-error.log
yarn-debug.log*
.yarn-integrity

.idea/
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gem "webpacker", "~> 5.0"
gem "turbolinks", "~> 5"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 2.7"
gem "kaminari"
gem "pry"
# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"
Expand Down
15 changes: 14 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.6.3)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
Expand Down Expand Up @@ -129,7 +141,7 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.4)
pry (0.14.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.3)
Expand Down Expand Up @@ -271,6 +283,7 @@ DEPENDENCIES
byebug
capybara (>= 3.26)
jbuilder (~> 2.7)
kaminari
listen (~> 3.3)
pg (~> 1.1)
pry
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ProjectsController < ApplicationController
before_action :set_project, only: %i[show edit update destroy]

def index
@projects = Project.order(:id)
@projects = Project.order(params[:sort]).page(params[:page]).per(3)
end

def show; end
Expand Down
6 changes: 6 additions & 0 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

<h2><%= link_to "New Project", new_project_path %><h2>

<%= link_to "Name", :sort => "name asc"%>
<%= link_to "Name reverse", :sort => "name desc"%>
<%= link_to "Description", :sort => "description asc" %>
<%= link_to "Description reverse", :sort => "description desc" %>
<% @projects.each do |project| %>
<div class="record">
<p><%= project.id %>. <%= link_to project.name, project_path(project) %></p>
Expand All @@ -10,3 +14,5 @@
<p><%= button_to "Destroy", project, method: :delete %></p>
</div>
<% end %>

<%= paginate @projects %>
14 changes: 14 additions & 0 deletions config/initializers/kaminari_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

Kaminari.configure do |config|
config.default_per_page = 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

0 comments on commit ac65df6

Please sign in to comment.