Add correct user to RelatedContentScore on creation
This commit is contained in:
@@ -28,7 +28,7 @@ class RelatedContentsController < ApplicationController
|
||||
private
|
||||
|
||||
def score(value)
|
||||
RelatedContent.find_by(id: params[:id]).score(value)
|
||||
RelatedContent.find_by(id: params[:id]).score(value, current_user)
|
||||
|
||||
render template: 'relationable/_refresh_score_actions'
|
||||
end
|
||||
|
||||
@@ -18,13 +18,13 @@ class RelatedContent < ActiveRecord::Base
|
||||
validates :parent_relationable_id, uniqueness: { scope: [:parent_relationable_type, :child_relationable_id, :child_relationable_type] }
|
||||
|
||||
after_create :create_opposite_related_content, unless: proc { opposite_related_content.present? }
|
||||
after_create :create_author_score
|
||||
|
||||
scope :not_hidden, -> { where('positive_score - negative_score / LEAST(nullif(positive_score + negative_score, 0), 1) >= ?', RELATED_CONTENT_SCORE_THRESHOLD) }
|
||||
scope :not_hidden, -> { where(hidden_at: nil) }
|
||||
|
||||
def score(value)
|
||||
RelatedContentsScore.create(user_id: current_user, related_content_id: self, score: value)
|
||||
RelatedContentsScore.create(user_id: current_user, related_content_id: opposite_related_content, score: value)
|
||||
def score(value, user)
|
||||
score_with_opposite(value, user)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -33,4 +33,13 @@ class RelatedContent < ActiveRecord::Base
|
||||
related_content = RelatedContent.create!(opposite_related_content: self, parent_relationable: child_relationable, child_relationable: parent_relationable)
|
||||
self.opposite_related_content = related_content
|
||||
end
|
||||
|
||||
def create_author_score
|
||||
score(1, author)
|
||||
end
|
||||
|
||||
def score_with_opposite(value, user)
|
||||
RelatedContentsScore.create(user: user, related_content: self, score: value)
|
||||
RelatedContentsScore.create(user: user, related_content: opposite_related_content, score: value)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user