Forum: Ruby on Rails Error Handling

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sainaba S. (Guest)
on 2006-01-06 12:33
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.
Frank S. (Guest)
on 2006-01-06 13:08
(Received via mailing list)
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
Alex Y. (Guest)
on 2006-01-06 13:17
(Received via mailing list)
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 :-)
Sainaba S. (Guest)
on 2006-01-06 14:53
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......
This topic is locked and can not be replied to.