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

@@ -4,7 +4,9 @@ class FavoriteGroupsController < ApplicationController
def index
params[:search][:creator_id] ||= params[:user_id]
@favorite_groups = FavoriteGroup.paginated_search(params).includes(model_includes(params))
@favorite_groups = FavoriteGroup.paginated_search(params)
@favorite_groups = @favorite_groups.includes(:creator) if request.format.html?
respond_with(@favorite_groups)
end
@@ -61,14 +63,6 @@ class FavoriteGroupsController < ApplicationController
private
def default_includes(params)
if ["json", "xml"].include?(params[:format])
[]
else
[:creator]
end
end
def check_write_privilege(favgroup)
raise User::PrivilegeError unless favgroup.editable_by?(CurrentUser.user)
end