controllers: refactor only param includes.
Add extra includes needed by the `only` param inside `respond_with`.
This commit is contained in:
@@ -5,7 +5,9 @@ class PostVotesController < ApplicationController
|
||||
rescue_with PostVote::Error, status: 422
|
||||
|
||||
def index
|
||||
@post_votes = PostVote.paginated_search(params, count_pages: true).includes(model_includes(params))
|
||||
@post_votes = PostVote.paginated_search(params, count_pages: true)
|
||||
@post_votes = @post_votes.includes(:user, post: :uploader) if request.format.html?
|
||||
|
||||
respond_with(@post_votes)
|
||||
end
|
||||
|
||||
@@ -22,14 +24,4 @@ class PostVotesController < ApplicationController
|
||||
|
||||
respond_with(@post)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[]
|
||||
else
|
||||
[:user, {post: [:uploader]}]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user