From db23d2090431ac26d7cce60fa7df096fa33afb7a Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 12 Nov 2013 11:25:02 -0300 Subject: [PATCH] Fix vote_fu search to handle polymorphic models --- vendor/plugins/vote_fu/lib/acts_as_voteable.rb | 4 ++-- vendor/plugins/vote_fu/lib/models/vote.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vendor/plugins/vote_fu/lib/acts_as_voteable.rb b/vendor/plugins/vote_fu/lib/acts_as_voteable.rb index c394152..7962260 100644 --- a/vendor/plugins/vote_fu/lib/acts_as_voteable.rb +++ b/vendor/plugins/vote_fu/lib/acts_as_voteable.rb @@ -149,9 +149,9 @@ module Juixe def voted_by?(voter, for_or_against = "all") options = (for_or_against == "all") ? {} : {:vote => (for_or_against ? 1 : -1)} - self.votes.exists?({:voter_id => voter.id, :voter_type => voter.class.name}.merge(options)) + self.votes.exists?({:voter_id => voter.id, :voter_type => voter.class.base_class.name}.merge(options)) end end end end -end \ No newline at end of file +end diff --git a/vendor/plugins/vote_fu/lib/models/vote.rb b/vendor/plugins/vote_fu/lib/models/vote.rb index 1e5a0c2..a428638 100644 --- a/vendor/plugins/vote_fu/lib/models/vote.rb +++ b/vendor/plugins/vote_fu/lib/models/vote.rb @@ -1,7 +1,7 @@ class Vote < ActiveRecord::Base - named_scope :for_voter, lambda { |*args| {:conditions => ["voter_id = ? AND voter_type = ?", args.first.id, args.first.type.name]} } - named_scope :for_voteable, lambda { |*args| {:conditions => ["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.type.name]} } + named_scope :for_voter, lambda { |*args| {:conditions => ["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name]} } + named_scope :for_voteable, lambda { |*args| {:conditions => ["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name]} } named_scope :recent, lambda { |*args| {:conditions => ["created_at > ?", (args.first || 2.weeks.ago).to_s(:db)]} } named_scope :descending, :order => "created_at DESC" @@ -12,6 +12,6 @@ class Vote < ActiveRecord::Base attr_accessible :vote, :voter, :voteable # Uncomment this to limit users to a single vote on each item. - #validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id] + validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id] end -- libgit2 0.21.2