Home > Blockchain >  How to increase users point when boolean is true
How to increase users point when boolean is true

Time:11-23

User model:

  has_many :battle_passes, dependent: :destroy
  after_create :ensure_battle_pass_present!

  has_many :challenges, through: :battle_passes 

A user has points. When a user completes a challenge (by an admin marking the challenge as complete) I want to increase that players points by the points the challenge awards. So it is an admin that updating the challenge for a user and marking it complete. How do I update the points for the correct user? Should that happen in the model or controller?

CodePudding user response:

You can set one callback on completion of challenge with challenge model like

after_save :update_points, if: :completed_challenge?

def update_points
  self.user.update(points:100)
end

  • Related