What's the best way to report errors on form fields not associated with a particular model in Rails? As an example, I have a form for the batch creation of user accounts with random users / passwords. It takes as inputs the quantity of users to make, information about what attributes all users should have, and information about the batch which is stored in a user_batches model associated with the created users.
Ideally there would be some errors_on
like way to list errors coming from the quantity field, which is associated with no model, the user information fields, associated with the user records that get created, and the user_batches model with minimal code.
This also applies to search forms and the like, which don't get run through AR validations. Any ideas?
You can add your own errors manually to your model object like this.
@user_batch.errors.add_to_base("Foo")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With