From 6d867de20f122687247c57e201aa41f8e912ccb4 Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Fri, 22 Jan 2021 02:39:58 +0000 Subject: [PATCH] Add way for controllers with different models to use the only parameter The /emails endpoint was passing in the "Email" model because that's how the emails controller classifies. This was to fix that, and to allow any other such cases in the future. --- app/controllers/application_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 13d1cb4f2..a9fb6e806 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -35,8 +35,10 @@ class ApplicationController < ActionController::Base return end + model = options[0]&.delete(:model) if subject.respond_to?(:includes) && (request.format.json? || request.format.xml?) - associations = ParameterBuilder.includes_parameters(params[:only], model_name) + model ||= model_name + associations = ParameterBuilder.includes_parameters(params[:only], model) subject = subject.includes(associations) end