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 PostAppealsController < ApplicationController
end
def index
@post_appeals = PostAppeal.paginated_search(params).includes(model_includes(params))
@post_appeals = PostAppeal.paginated_search(params)
if request.format.html?
@post_appeals = @post_appeals.includes(:creator, post: [:appeals, :uploader, :approver])
else
@post_appeals = @post_appeals.includes(:post)
end
respond_with(@post_appeals)
end
@@ -26,14 +33,6 @@ class PostAppealsController < ApplicationController
private
def default_includes(params)
if ["json", "xml"].include?(params[:format])
[:post]
else
[:creator, {post: [:appeals, :uploader, :approver]}]
end
end
def post_appeal_params
params.fetch(:post_appeal, {}).permit(%i[post_id reason])
end