controllers: refactor only param includes.
Add extra includes needed by the `only` param inside `respond_with`.
This commit is contained in:
@@ -6,7 +6,14 @@ class PostVersionsController < ApplicationController
|
||||
respond_to :js, only: [:undo]
|
||||
|
||||
def index
|
||||
@post_versions = PostArchive.paginated_search(params).includes(model_includes(params))
|
||||
@post_versions = PostArchive.paginated_search(params)
|
||||
|
||||
if request.format.html?
|
||||
@post_versions = @post_versions.includes(:updater, post: [:uploader, :versions])
|
||||
else
|
||||
@post_versions = @post_versions.includes(post: :versions)
|
||||
end
|
||||
|
||||
respond_with(@post_versions)
|
||||
end
|
||||
|
||||
@@ -26,14 +33,6 @@ class PostVersionsController < ApplicationController
|
||||
"PostArchive"
|
||||
end
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[:updater, {post: [:versions]}]
|
||||
else
|
||||
[:updater, {post: [:uploader, :versions]}]
|
||||
end
|
||||
end
|
||||
|
||||
def set_timeout
|
||||
PostArchive.connection.execute("SET statement_timeout = #{CurrentUser.user.statement_timeout}")
|
||||
yield
|
||||
|
||||
Reference in New Issue
Block a user