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.
This commit is contained in:
BrokenEagle
2021-01-22 02:39:58 +00:00
parent 6ca007ee1f
commit 6d867de20f

View File

@@ -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