Skip to content

Commit

Permalink
Add pagination to events#index view
Browse files Browse the repository at this point in the history
  • Loading branch information
KattyaCuevas committed Dec 12, 2023
1 parent b40b7ab commit c3af7a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true
module Admin
class EventsController < AdminController
include Pagy::Backend

before_action :authorize_event
before_action :set_event, only: %w[edit update destroy]

def index
@events = Event.includes(:speakers).order(date: :desc)
@pagy, @events = pagy(Event.includes(:speakers).order(date: :desc))
end

def new
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module ApplicationHelper
include Pagy::Frontend

def canonical_url
request.base_url + request.path
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/events/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
</tbody>
</table>
</div>
<div class="d-flex justify-content-end">
<%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %>
</div>
</div>
</div>

0 comments on commit c3af7a5

Please sign in to comment.