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. -- Posted via http://www.ruby-forum.com/.
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 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? > > Thanks.. > > Sainaba. >
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 :-) -- Alex
Frank Spychalski 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 > FrankHi, 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...... -- Posted via http://www.ruby-forum.com/.