Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors on non model fields in rails

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?

like image 411
Andrew Cholakian Avatar asked Mar 02 '09 01:03

Andrew Cholakian


1 Answers

You can add your own errors manually to your model object like this.

@user_batch.errors.add_to_base("Foo")
like image 170
jdl Avatar answered Oct 19 '22 13:10

jdl