Skip to content

Commit 301231c

Browse files
committed
Create paginable/research_outputs_controller.rb
1 parent 8ecced5 commit 301231c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module Paginable
4+
# Controller for paginating/sorting/searching the research_outputs table
5+
class ResearchOutputsController < ApplicationController
6+
include Paginable
7+
8+
after_action :verify_authorized
9+
10+
# GET /paginable/plans/:plan_id/research_outputs
11+
def index
12+
@plan = Plan.find_by(id: params[:plan_id])
13+
# Same assignment as app/controllers/research_outputs_controller.rb
14+
research_outputs = ResearchOutput.includes(:repositories).where(plan_id: @plan.id)
15+
# Same authorize handling as app/controllers/research_outputs_controller.rb
16+
# `|| ResearchOutput.new(plan_id: @plan.id)` prevents Pundit::NotDefinedError when a direct
17+
# GET /paginable/plans/:id/research_outputs request is made on a plan with 0 research_outputs
18+
authorize(research_outputs.first || ResearchOutput.new(plan_id: @plan.id))
19+
paginable_renderise(
20+
partial: 'index',
21+
scope: research_outputs,
22+
query_params: { sort_field: 'research_outputs.title' },
23+
format: :json
24+
)
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)