controllers: refactor only param includes.

Add extra includes needed by the `only` param inside `respond_with`.
This commit is contained in:
evazion
2020-02-14 20:08:42 -06:00
parent 8649ff6dbe
commit 2564e885c8
42 changed files with 153 additions and 387 deletions

View File

@@ -25,28 +25,18 @@ class ApplicationController < ActionController::Base
private
def respond_with(subject, *options, &block)
@current_item = subject
if params[:action] == "index" && is_redirect?(subject)
redirect_to_show(subject)
else
super
return
end
end
def model_includes(params, model = nil)
if params[:only] && ["json", "xml"].include?(params[:format])
includes_array = ParameterBuilder.includes_parameters(params[:only], model_name)
elsif params[:action] == "index"
includes_array = default_includes(params)
else
includes_array = []
if request.format.json? || request.format.xml?
associations = ParameterBuilder.includes_parameters(params[:only], model_name)
subject = subject.includes(associations)
end
includes_array
end
def default_includes(*)
[]
@current_item = subject
super
end
def model_name