From 080ea5b5ab66653769f4a9dfd4f6d225abc88a02 Mon Sep 17 00:00:00 2001 From: James McCarthy Date: Wed, 21 Sep 2011 14:48:53 +0100 Subject: [PATCH] Simplifies Follower#follow. --- lib/acts_as_follower/follower.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/acts_as_follower/follower.rb b/lib/acts_as_follower/follower.rb index 2c8da0a..168c09a 100644 --- a/lib/acts_as_follower/follower.rb +++ b/lib/acts_as_follower/follower.rb @@ -28,9 +28,8 @@ def follow_count # Creates a new follow record for this instance to follow the passed object. # Does not allow duplicate records to be created. def follow(followable) - follow = get_follow(followable) - if follow.blank? && self != followable - Follow.create(:followable => followable, :follower => self) + if self != followable + self.follows.find_or_create_by_followable_id_and_followable_type(followable.id, parent_class_name(followable)) end end