I have a new API attribute which is an array of hashes and I would like to validate it as part of built-in rails validation. Since this is a complex object I'm validating I am not finding any valid examples to refer from.
The parameter name is books
which are an array of hashes and each hash has three properties genre
which should be an enum of three possible values and authors
which should be an array of integers and bookId
which should be an integer.
Something like this books: [{bookId: 4, genre: "crime", authors: [2, 3, 4]}]
If it's something like an array I can see the documentation for it https://guides.rubyonrails.org/active_record_validations.html here but I am not finding any examples of the above scenarios.
I'm using rails 4.2.1 with ruby 2.3.7 it would be great if you could help me with somewhere to start with this.
For specifically, enum validation I did find a good answer here How do I validate members of an array field?. The trouble is when I need to use this in an array of hashes.