I have a Game model which has_many Rounds which has_many Shots.
Per game, each cup hit with a shot should be unique. This is easy enough to do with validates_uniqueness_of :cup using a scope of :game_id.
However, how do I validate that each Shot is an increment of +1 of the last shot? I cannot have users select their first shot as having made cup 4. This would make no sense.
My form is using form_for @round which accepts nested attributes for exactly 6 shots.
How do I implement this validation? Do I need to refactor my view or completely rethink this?
Since you are using Rails 3, you get some nice options here. I’m not sure that I understand your problem completely, but I’m assuming that you want some type of validation where the score starts at 1 and increments each time.
Here’s a test.
And an example model.
Test output: