Skip to content

Commit

Permalink
Create paginable/research_outputs_controller.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronskiba committed Feb 10, 2025
1 parent 8ecced5 commit 301231c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/controllers/paginable/research_outputs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Paginable
# Controller for paginating/sorting/searching the research_outputs table
class ResearchOutputsController < ApplicationController
include Paginable

after_action :verify_authorized

# GET /paginable/plans/:plan_id/research_outputs
def index
@plan = Plan.find_by(id: params[:plan_id])
# Same assignment as app/controllers/research_outputs_controller.rb
research_outputs = ResearchOutput.includes(:repositories).where(plan_id: @plan.id)
# Same authorize handling as app/controllers/research_outputs_controller.rb
# `|| ResearchOutput.new(plan_id: @plan.id)` prevents Pundit::NotDefinedError when a direct
# GET /paginable/plans/:id/research_outputs request is made on a plan with 0 research_outputs
authorize(research_outputs.first || ResearchOutput.new(plan_id: @plan.id))
paginable_renderise(
partial: 'index',
scope: research_outputs,
query_params: { sort_field: 'research_outputs.title' },
format: :json
)
end
end
end

0 comments on commit 301231c

Please sign in to comment.