# Error Handling

**URL:** <https://www.ruby-forum.com/t/error-handling/94542>\
**Category:** Rails\
**Created:** [January 6, 2006, 11:33am UTC](https://www.ruby-forum.com/t/error-handling/94542 "2006-01-06T11:33:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 6, 2006, 11:33am UTC](https://www.ruby-forum.com/t/error-handling/94542/1 "2006-01-06T11:33:58Z")

</div>

Hi,

I am doing a project on invoice. For that I have to use a page both for  
crating new invoices and for updation of existing invoices. The problem  
is that when an error occures, I can’t maintain the same page for error  
correction. How can I redirect it from the controller ? Or can I display  
ruby errors before submit of the page in ruby?

Thanks…

Sainaba.

---

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 6, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/error-handling/94542/2 "2006-01-06T12:08:12Z")

</div>

I might be wrong, but it should be possible to use the same page. Just  
fill your form with:

- nothing for a new invoice
- model data for editing an invoice
- form data for error correction

bye  
Frank

---

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 6, 2006, 12:17pm UTC](https://www.ruby-forum.com/t/error-handling/94542/3 "2006-01-06T12:17:14Z")

</div>

sainaba sainu wrote:

> Hi,
> 
> I am doing a project on invoice. For that I have to use a page both for  
> crating new invoices and for updation of existing invoices. The problem  
> is that when an error occures, I can’t maintain the same page for error  
> correction. How can I redirect it from the controller ? Or can I display  
> ruby errors before submit of the page in ruby?

There are a couple of things you can do. The first is to do what the  
scaffolded code does, which is redirect back to the edit/new form if the  
object doesn’t save, and display the error messages. Take a look at the  
scaffold code to see how that works - the form fields get filled out  
with the same data as was submitted.

The second is a little more fun, but a little more involved. On any  
change to the form data, you can submit it to an AJAX validator action,  
and display any errors back to the user. When the validator comes back  
with no errors, you can allow the form to be submitted to the  
update/create action.

I’ve been meaning to try the second method out, but haven’t had a decent  
excuse yet 🙂

---

<div class="post-metadata">

**Author:** ![sainaba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@sainaba](https://www.ruby-forum.com/u/sainaba)\
**Post date:** [January 6, 2006, 1:53pm UTC](https://www.ruby-forum.com/t/error-handling/94542/4 "2006-01-06T13:53:15Z")

</div>

Frank S. wrote:

> I might be wrong, but it should be possible to use the same page. Just  
> fill your form with:
> 
> - nothing for a new invoice
> - model data for editing an invoice
> - form data for error correction
> 
> bye  
> Frank

Hi,

Thanks for the comments.

It worked with return of nothing to the page  
But I got a new problem with validation of date in the invoice page…

Is rail has any method to validate a date select field?

It returns MultiparameterAssignmentError on invalid data?

Any suggetions to validate date?

Thans in advance…
