controllers: refactor only param includes.
Add extra includes needed by the `only` param inside `respond_with`.
This commit is contained in:
@@ -5,7 +5,8 @@ class CommentVotesController < ApplicationController
|
||||
rescue_with CommentVote::Error, ActiveRecord::RecordInvalid, status: 422
|
||||
|
||||
def index
|
||||
@comment_votes = CommentVote.paginated_search(params, count_pages: true).includes(model_includes(params))
|
||||
@comment_votes = CommentVote.paginated_search(params, count_pages: true)
|
||||
@comment_votes = @comment_votes.includes(:user, comment: [:creator, post: [:uploader]]) if request.format.html?
|
||||
respond_with(@comment_votes)
|
||||
end
|
||||
|
||||
@@ -20,14 +21,4 @@ class CommentVotesController < ApplicationController
|
||||
@comment.unvote!
|
||||
respond_with(@comment)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_includes(params)
|
||||
if ["json", "xml"].include?(params[:format])
|
||||
[]
|
||||
else
|
||||
[:user, {comment: [:creator, {post: [:uploader]}]}]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user