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

@@ -8,7 +8,14 @@ class PostFlagsController < ApplicationController
end
def index
@post_flags = PostFlag.paginated_search(params).includes(model_includes(params))
@post_flags = PostFlag.paginated_search(params)
if request.format.html?
@post_flags = @post_flags.includes(:creator, post: [:flags, :uploader, :approver])
else
@post_flags = @post_flags.includes(:post)
end
respond_with(@post_flags)
end
@@ -26,16 +33,6 @@ class PostFlagsController < ApplicationController
private
def default_includes(params)
if ["json", "xml"].include?(params[:format])
[:post]
else
includes_array = [{post: [:flags, :uploader, :approver]}]
includes_array << :creator if CurrentUser.is_moderator?
includes_array
end
end
def post_flag_params
params.fetch(:post_flag, {}).permit(%i[post_id reason])
end