I’m writing a simple project management app as a learning exercise in Rails.
I have a task model, and a user model. The task model has a user field denoting which user has claimed a given task.
There are a couple of things I want to enforce in the model level but am not sure how:
- Each user may claim up to five tasks, and no more.
- Each user may only claim tasks for their own (i.e, the
userfield can be set to the currently active user, and not to any other user). In other words, you can’t assign tasks – users may only claim them.
Is trying to enforce these as validations the right thing to do? Could you point me in the direction of the validations I need? Should I write my own?
Thank you.
You should add your own validations. There is no default for the ones you are looking for. Here is some sample code:
The other one is like the above, only the if changes, so i believe you can look into this and adapt to your own needs.