Commit cf523ca39dc2940e6460083107c941c57e460f49
Committed by
Tom Cocca
1 parent
f53b8ae0
Exists in
master
and in
3 other branches
acts_as_followable.rb's followed_by? method is working (again?)... and simplifie…
…d lookup there a lil bit.. no foreach iteration anymore Signed-off-by: Tom Cocca <tom.cocca@gmail.com>
Showing
1 changed file
with
10 additions
and
6 deletions
Show diff stats
lib/acts_as_followable.rb
... | ... | @@ -29,14 +29,18 @@ module ActiveRecord #:nodoc: |
29 | 29 | end |
30 | 30 | |
31 | 31 | # Returns true if the current instance is followed by the passed record. |
32 | - def followed_by?(follwer) | |
33 | - rtn = false | |
34 | - self.follows.each do |f| | |
35 | - rtn = true if follwer.id == f.follower_id && parent_class_name(follwer) == f.follower_type | |
36 | - end | |
37 | - rtn | |
32 | + def followed_by?(follower) | |
33 | + self.follows.find(:first, :conditions => ["follower_id = ? AND follower_type = ?", follower.id, parent_class_name(follower)]) ? true : false | |
38 | 34 | end |
39 | 35 | |
36 | + # Retrieves the parent class name if using STI. | |
37 | + def parent_class_name(obj) | |
38 | + if obj.class.superclass != ActiveRecord::Base | |
39 | + return obj.class.superclass.name | |
40 | + end | |
41 | + | |
42 | + return obj.class.name | |
43 | + end | |
40 | 44 | end |
41 | 45 | |
42 | 46 | end | ... | ... |