Commit db23d2090431ac26d7cce60fa7df096fa33afb7a
1 parent
edbc6fc1
Exists in
master
and in
29 other branches
Fix vote_fu search to handle polymorphic models
Showing
2 changed files
with
5 additions
and
5 deletions
Show diff stats
vendor/plugins/vote_fu/lib/acts_as_voteable.rb
| ... | ... | @@ -149,9 +149,9 @@ module Juixe |
| 149 | 149 | |
| 150 | 150 | def voted_by?(voter, for_or_against = "all") |
| 151 | 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 | 153 | end |
| 154 | 154 | end |
| 155 | 155 | end |
| 156 | 156 | end |
| 157 | -end | |
| 158 | 157 | \ No newline at end of file |
| 158 | +end | ... | ... |
vendor/plugins/vote_fu/lib/models/vote.rb
| 1 | 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 | 5 | named_scope :recent, lambda { |*args| {:conditions => ["created_at > ?", (args.first || 2.weeks.ago).to_s(:db)]} } |
| 6 | 6 | named_scope :descending, :order => "created_at DESC" |
| 7 | 7 | |
| ... | ... | @@ -12,6 +12,6 @@ class Vote < ActiveRecord::Base |
| 12 | 12 | attr_accessible :vote, :voter, :voteable |
| 13 | 13 | |
| 14 | 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 | 17 | end | ... | ... |