alex nesbitt
2006-Jan-04 04:32 UTC
[Rails] how to display validation error messages for multiple record form
I am trying to figure out how to display model validation error messages for a multiple record form. My form is for setting up new accounts and collects information for two models - Accounts and Users. My create method collects the parameters from the form and adds them to a Account object and a User object then runs account.valid? and user.valid?. If it''s valid it updates the models ok, if not valid I get error messages for accounts to display on my form page but not user validation error messages. I have validations set in both models. I would like to collect all the validation error messages from both models and put them in one error display box at the top of the form and then highlight any input boxes that need to be fixed. Any ideas how to do this? thanks Alex -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060104/da592973/attachment.html
Navjeet Chabbewal
2006-Jan-24 04:56 UTC
[Rails] Re: how to display validation error messages for multiple re
Alex, I am facing a similar issue. Did u find a solution to this problem? -Jeet alex nesbitt wrote:> I am trying to figure out how to display model validation error messages > for > a multiple record form. > > My form is for setting up new accounts and collects information for two > models - Accounts and Users. > > My create method collects the parameters from the form and adds them to > a > Account object and a User object then runs account.valid? and > user.valid?. > If it''s valid it updates the models ok, if not valid I get error > messages > for accounts to display on my form page but not user validation error > messages. I have validations set in both models. > > I would like to collect all the validation error messages from both > models > and put them in one error display box at the top of the form and then > highlight any input boxes that need to be fixed. > > Any ideas how to do this? > > thanks > Alex-- Posted via http://www.ruby-forum.com/.
Bob Silva
2006-Jan-24 05:47 UTC
[Rails] Re: how to display validation error messages for multiple re
One solution is to grab the errors and loop them yourself. errors = Class1.errors.full_messages + Class2.errors.full_messages Better yet, write a plugin for error_messages_for that will take a single object name or hash of object names to display errors for? I have an error_messages_for plugin coming soon that I may incorporate this into. I''ll look at that later tonight. Cheers, Bob Silva> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of Navjeet Chabbewal > Sent: Monday, January 23, 2006 8:57 PM > To: rails@lists.rubyonrails.org > Subject: [Rails] Re: how to display validation error messages for multiple > re > > Alex, I am facing a similar issue. Did u find a solution to this > problem? > > -Jeet > > alex nesbitt wrote: > > I am trying to figure out how to display model validation error messages > > for > > a multiple record form. > > > > My form is for setting up new accounts and collects information for two > > models - Accounts and Users. > > > > My create method collects the parameters from the form and adds them to > > a > > Account object and a User object then runs account.valid? and > > user.valid?. > > If it''s valid it updates the models ok, if not valid I get error > > messages > > for accounts to display on my form page but not user validation error > > messages. I have validations set in both models. > > > > I would like to collect all the validation error messages from both > > models > > and put them in one error display box at the top of the form and then > > highlight any input boxes that need to be fixed. > > > > Any ideas how to do this? > > > > thanks > > Alex > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails