If you have a look at the Association callbacks section of the docs, you'll see this example:
class Project
has_and_belongs_to_many :developers, after_add: :evaluate_velocity
def evaluate_velocity(developer)
...
end
end
That's not the has_many
relationship that you have but it is close enough. If you look at the evaluate_velocity
method, you'll see that the developer
in question is passed as an argument by the :after_add
callback. You're getting an ArgumentError about your update_remaining_nutrients
being called with one argument when it doesn't want any and that matches what the the example suggests would happen.
Try this:
def update_remaining_nutrients(meal)
# Do interesting things with `meal` in here...
end