Validation of array elements

Hi, I’m not too sure how to go about this. I have a validation in my model, which validates the presences_of no-activity. This is an array of containers with no_activity on them, ( I check to see if the array is empty), but the requirement is to check each container in the array and display an error for each container that is empty and display an error for each of them.

I’m having a hard time conceptualizing your models and schema. Could you post the relevant portions of them?

If you need to address each of the elements of your array individually, you can do so using its numerical index (zero-based number). If your array elements have names, or have some other organizational scheme other than simple order, you might have a hash instead.

But since you’re in Rails, you may want to just make a model for these containers, and validate them individually as to having activity. The parent record would has_many of them, and each would belong_to that parent. Then you can use a nested form, and the accepts_nested_attributes macro in your parent model to allow them to be updated individually within the context of a parent record.