Skip to content

Commit 2aebcd2

Browse files
authored
Add pagination (#196)
2 parents 790a9a0 + d044b1b commit 2aebcd2

File tree

19 files changed

+426
-8
lines changed

19 files changed

+426
-8
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ gem "image_processing", "~> 1.14"
5151

5252
gem "acts-as-taggable-on"
5353
gem "aws-sdk-s3", require: false
54+
gem "pagy"
5455
gem "requestjs-rails"
5556

5657
group :development, :test do

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ GEM
283283
nokogiri (1.18.8-x86_64-linux-musl)
284284
racc (~> 1.4)
285285
ostruct (0.6.1)
286+
pagy (9.3.4)
286287
parallel (1.26.3)
287288
parser (3.3.7.2)
288289
ast (~> 2.4.1)
@@ -510,6 +511,7 @@ DEPENDENCIES
510511
jbuilder
511512
kamal
512513
letter_opener
514+
pagy
513515
pg (~> 1.1)
514516
propshaft
515517
puma (>= 5.0)

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RESET := \033[0m
1010

1111
# Commands configuration
1212
COMPOSE_CMD = COMPOSE_PROJECT_NAME=$(PROJECT_NAME) docker compose -f docker-compose.dev.yml
13-
DOCKER_TEST_CMD = $(COMPOSE_CMD) exec app bundle exec rspec --format documentation
13+
DOCKER_TEST_CMD = $(COMPOSE_CMD) exec app bundle exec bash -c "export RAILS_ENV=test && rspec --format documentation"
1414
EXEC_CMD = $(COMPOSE_CMD) exec app
1515

1616
.PHONY: help build rebuild stop start restart logs shell console format test test_fast db_reset migrate clean clean_volumes
@@ -69,7 +69,7 @@ format:
6969
$(EXEC_CMD) bundle exec rubocop --autocorrect-all
7070

7171
test:
72-
export RAILS_ENV=test $(DOCKER_TEST_CMD)
72+
$(DOCKER_TEST_CMD)
7373

7474
test_fast:
7575
$(DOCKER_TEST_CMD) --fail-fast

app/controllers/tags_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22
class TagsController < ApplicationController
3+
include Pagy::Backend
4+
35
before_action :set_tag, only: [ :show, :edit, :update, :destroy ]
46

57
def index
6-
@tags = Tag.includes(:cognates, :reverse_cognates).references(:tag)
8+
@pagy, @tags = pagy(Tag.includes(:cognates, :reverse_cognates).references(:tag))
79
end
810

911
def new

app/controllers/topics_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
class TopicsController < ApplicationController
2+
include Pagy::Backend
3+
24
before_action :set_topic, only: [ :show, :edit, :tags, :update, :destroy, :archive ]
35

46
def index
5-
@topics = scope.search_with_params(search_params)
7+
@pagy, @topics = pagy(scope.search_with_params(search_params))
68
@available_providers = other_available_providers
79
@languages = scope.map(&:language).uniq.sort_by(&:name)
810
end

app/controllers/users_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
class UsersController < ApplicationController
2+
include Pagy::Backend
3+
24
before_action :redirect_contributors
35
before_action :set_user, only: %i[ edit update destroy ]
46

57
def index
6-
@users = User.all.search_with_params(user_search_params)
8+
@pagy, @users = pagy(User.all.search_with_params(user_search_params))
79
end
810

911
def new

app/helpers/application_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module ApplicationHelper
2+
include Pagy::Frontend
3+
24
def flash_class(level)
35
case level
46
when "notice" then "alert-light-success"

app/views/tags/index.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
</div>
2929
</div>
3030
</div>
31+
<div class="card-footer d-flex justify-content-end">
32+
<%== pagy_bootstrap_nav(@pagy) %>
33+
</div>
3134
</div>
3235
</div>
3336
</div>

app/views/topics/index.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<% end %>
3939
</div>
4040
</div>
41+
<div class="card-footer d-flex justify-content-end">
42+
<%== pagy_bootstrap_nav(@pagy) %>
43+
</div>
4144
</div>
4245
<% end %>
4346
</div>

app/views/users/index.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
<tbody>
7272
</table>
7373
</div>
74+
<div class="card-footer d-flex justify-content-end">
75+
<%== pagy_bootstrap_nav(@pagy) %>
76+
</div>
7477
</div>
7578
</section>
7679
</div>

0 commit comments

Comments
 (0)