Skip to content

Commit

Permalink
Uses first_or_create in Follower#follow
Browse files Browse the repository at this point in the history
Uses first_or_create! instead of deprecated find_or_create. Old way
causes #follow to fail in certain Rails versions

first_or_create is available since Rails 3.2, find_or_create is
deprecated in Rails 4.0
  • Loading branch information
Justin Reese authored and LeFnord committed Jan 21, 2021
1 parent fbf723e commit bd05e36
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/acts_as_follower/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def follow_count
# Does not allow duplicate records to be created.
def follow(followable)
if self != followable
self.follows.find_or_create_by(followable_id: followable.id, followable_type: parent_class_name(followable))
params = {followable_id: followable.id, followable_type: parent_class_name(followable)}
self.follows.where(params).first_or_create!
end
end

Expand Down

0 comments on commit bd05e36

Please sign in to comment.