Hello stackoverflowers!!!!
I have 2 models:
models/user.rb
class User
has_many :colleagues
before_save :give_points
private
def give_points
if self.name == "Jordie"
colleague1 = Colleague.find_by_name("Ann")
colleague2 = Colleague.find_by_name("Beth")
colleague1.increment!(:bonus, by = self.points)
colleague1.decrement!(:bonus, by = self.points)
end
end
end
models/user.rb
class Colleague
belongs_to :user
end
Matter fact I want to increment and decrement Ann and Beth when the Jordie gives them bonuses.But I get the following:
undefined method `increment!' for nil:NilClass
What's the best way to handle this.I'm really confused by how to retrieve a specific object and increment it's attribute