File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
app/controllers/paginable Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments