Commit db23d2090431ac26d7cce60fa7df096fa33afb7a

Authored by Victor Costa
1 parent edbc6fc1

Fix vote_fu search to handle polymorphic models

vendor/plugins/vote_fu/lib/acts_as_voteable.rb
@@ -149,9 +149,9 @@ module Juixe @@ -149,9 +149,9 @@ module Juixe
149 149
150 def voted_by?(voter, for_or_against = "all") 150 def voted_by?(voter, for_or_against = "all")
151 options = (for_or_against == "all") ? {} : {:vote => (for_or_against ? 1 : -1)} 151 options = (for_or_against == "all") ? {} : {:vote => (for_or_against ? 1 : -1)}
152 - self.votes.exists?({:voter_id => voter.id, :voter_type => voter.class.name}.merge(options)) 152 + self.votes.exists?({:voter_id => voter.id, :voter_type => voter.class.base_class.name}.merge(options))
153 end 153 end
154 end 154 end
155 end 155 end
156 end 156 end
157 -end  
158 \ No newline at end of file 157 \ No newline at end of file
  158 +end
vendor/plugins/vote_fu/lib/models/vote.rb
1 class Vote < ActiveRecord::Base 1 class Vote < ActiveRecord::Base
2 2
3 - named_scope :for_voter, lambda { |*args| {:conditions => ["voter_id = ? AND voter_type = ?", args.first.id, args.first.type.name]} }  
4 - named_scope :for_voteable, lambda { |*args| {:conditions => ["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.type.name]} } 3 + named_scope :for_voter, lambda { |*args| {:conditions => ["voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name]} }
  4 + named_scope :for_voteable, lambda { |*args| {:conditions => ["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name]} }
5 named_scope :recent, lambda { |*args| {:conditions => ["created_at > ?", (args.first || 2.weeks.ago).to_s(:db)]} } 5 named_scope :recent, lambda { |*args| {:conditions => ["created_at > ?", (args.first || 2.weeks.ago).to_s(:db)]} }
6 named_scope :descending, :order => "created_at DESC" 6 named_scope :descending, :order => "created_at DESC"
7 7
@@ -12,6 +12,6 @@ class Vote &lt; ActiveRecord::Base @@ -12,6 +12,6 @@ class Vote &lt; ActiveRecord::Base
12 attr_accessible :vote, :voter, :voteable 12 attr_accessible :vote, :voter, :voteable
13 13
14 # Uncomment this to limit users to a single vote on each item. 14 # Uncomment this to limit users to a single vote on each item.
15 - #validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id] 15 + validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
16 16
17 end 17 end