I have a link on a form that allows for infinite new records to be
created.
i.e. Clicking “Add new record” basically renders the _new partial and
appends it to a div.
The model contains validates_uniqueness_of and validates_presence_of a
few fields.
This is all well and good, however, when validation fails at the model
level, the users don’t get any feedback or explanation as to why the
creation of the model failed.
Is there a technique for validating these types of records? and giving
the user some sort of feedback?
level, the users don’t get any feedback or explanation as to why the
creation of the model failed.
How so? Are you sending the form via Ajax? If yes, do you use
Ajax.Request or Updater? Anyway, you have plenty of options. If you
are using Ajax, you can use RJS (or return plain javascript) that
replaces the form with one with all the error messages. It can also
add another error message to the page. If you’re not using ajax, just
render the form again just like the standard resource scaffolding does
and it will display the errors.
Is there a technique for validating these types of records? and giving
the user some sort of feedback?
Well, you must send the data to the server, right? So you have exactly
the same mechanisms as always at your disposal. Only relaying them to
the UI is a bit different and perhaps trickier.