What I need to do is something like a bonus system. Let’s say I have a user and number of posts. When user reaches some count on posts (i.e. 100, 300, 550 etc) I want to give him new rank and “money” bonus. But if I’ll check it on new post save, how do I not five this bonus twice or more times (i.e. if posts > n { give bonus; }). How do I make this happen only once?
I thought about having a separate column in DB like bonus_given but how do I use it for different ranks? I don’t know why but I guess the solution of this problem.
PS. I use ruby as my language.
I think you gave the answer yourself. You give the user a new rank. You could check if the user needs to be promoted to a higher rank, and if that’s the case, promote him and give the bonus.
So for example:
Rank1 is < 100
Rank2 is >= 100 && < 300
Rank3 is >= 300 && < 550
Rank4 is >= 500
If a user saves his 100th post, and is Rank1, he should be promoted to Rank2 and be given “money” bonus.
This way you’ll be more flexible if you later on decide to add more Ranks/Different ranges.