diff --git a/app/controllers/post_votes_controller.rb b/app/controllers/post_votes_controller.rb index f02e1bc4c..87009f197 100644 --- a/app/controllers/post_votes_controller.rb +++ b/app/controllers/post_votes_controller.rb @@ -1,11 +1,11 @@ class PostVotesController < ApplicationController - before_action :voter_only, only: [:create, :destroy] + before_action :voter_only skip_before_action :api_check respond_to :js, :json, :xml, :html rescue_with PostVote::Error, status: 422 def index - @post_votes = PostVote.includes(:post, :user).paginated_search(params) + @post_votes = PostVote.includes(:user, post: [:uploader]).paginated_search(params) respond_with(@post_votes) end diff --git a/app/models/forum_post_vote.rb b/app/models/forum_post_vote.rb index d2780680c..9637aca8f 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -8,9 +8,15 @@ class ForumPostVote < ApplicationRecord scope :by, ->(user_id) {where(creator_id: user_id)} scope :excluding_user, ->(user_id) {where("creator_id <> ?", user_id)} + def self.forum_post_matches(params) + return all if params.blank? + where(forum_post_id: ForumPost.search(params).reorder(nil).select(:id)) + end + def self.search(params) q = super q = q.search_attributes(params, :creator, :forum_post_id, :score) + q = q.forum_post_matches(params[:forum_post]) q.apply_default_order(params) end diff --git a/app/models/user.rb b/app/models/user.rb index 8607e4a88..117fc3a98 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -89,6 +89,7 @@ class User < ApplicationRecord has_many :artist_versions, foreign_key: :updater_id has_many :artist_commentary_versions, foreign_key: :updater_id has_many :comments, foreign_key: :creator_id + has_many :comment_votes, dependent: :destroy has_many :wiki_page_versions, foreign_key: :updater_id has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy has_many :forum_post_votes, dependent: :destroy, foreign_key: :creator_id diff --git a/app/views/comment_votes/index.html.erb b/app/views/comment_votes/index.html.erb index a0210c550..d6f9e290c 100644 --- a/app/views/comment_votes/index.html.erb +++ b/app/views/comment_votes/index.html.erb @@ -44,7 +44,9 @@
<%= time_ago_in_words_tagged(forum_post_vote.updated_at) %>
+