Complex Error Handling

I’ve got a model that has to check other objects before it is valid.
If there are problems with the other objects, I want to report that
and also give the template access to the offending objects. The
regular errors object doesn’t seem suited to this. Is there another
way?

Here’s a better explanation of what’s going on:

Users are allowed to enter “events”. If they would like to, they can
associate these events with a “trip”. However, if they do that, the
time range specified for the trip needs to include the time of each of
the individual events.

So, if the user goes to edit a trip and changes the time range, I need
to go through all the events associated with the trip and make sure
the times fall within the new range. If an event has a time outside
that range, I’d like to give the user an error message letting them
know what happened and even let them edit the event on the spot. So,
I need a way to pass the actual event object (so I can get to all of
its attributes, including ID) to the template, not just text about it.

Is there a good way to do this? I’m not even sure how to pass
something more complex out of the model than just the standard text
message.

Thanks!

Curtis H.

Curtis Hawthorne wrote:

I’ve got a model that has to check other objects before it is valid.
If there are problems with the other objects, I want to report that
and also give the template access to the offending objects. The
regular errors object doesn’t seem suited to this. Is there another
way?

You could use validates_associated for that purpose, and then inspect
event.errors or trip.errors to see what the issues are.

Setting the necessary variables for the view to display what’s going on
is best done in the controller, and I can recommend implementing the
time span stuff in the models.


Roderick van Domburg
http://www.nedforce.com