Error messaging for a form without ActiveRecord model

I have a form that has no ActiveRecord model behind it, it is just
composed of random fields like “email_address”, “email_body”, etc.
Even though there is no model, some of these fields are required, and I
would like to use the built-in Rails methods for automatically showing
errors in the form. Unfortunataely, I can only see how to do this if
the form is based on an object whose model extends ActiveRecord. What
is the best way to use all the error message functionaity?

thanks,
Jeff

Hey Jeff,

I believe the builtin error_messages_for helper simples calls the method
errors on the object in question.

So I say check out what is returned when u call .errors on a
ActiveRecord
object with validation errors. Then basically structure your error
messages
to replicate this behavior. Then you will be able to use
error_messages_for
on both ActiveRecord objects as well as your custom objects.

HTH
~Rohith

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs