-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi All-- I have some validations in one of my models: class MyModel < ActiveRecord::Base validates_format_of :zip_code, :with => /\A\d{5}(-\d{4})?\Z/, :message => "Zip code does not match the format of 12345(-6789)." end Now, my controller has ''new'' and ''create'' methods that look like: def new @m = MyModel.new @categories = SomeCategory.find_all end create @m = MyModel.new(@params[''m'']) if @m.save redirect_to :action => ''list'' else @categories = SomeCategory.find_all render_action ''new'' end end Finally, my new.rhtml contains, among other things, [snip] <%= error_messages_for ''m'' %> [snip] When my ''new'' form posts to ''create'' with an invalid zip code, it gets bounced back to ''new'' (as expected), except that it displays the zip code error twice! I''ve been knocking my head against the wall for hours trying to figure out what is going on. I added a call to <%= debug @m %> in ''new'' and it clearly shows that both errors are in the @m variable. Does anyone know where the second error is coming from? I thought that I was doing the validation/error reporting correctly per the instructions here: http://wiki.rubyonrails.com/rails/show/HowtoValidate But I seem to have taken a wrong turn somewhere...this is with rails v0.11.1, WinXP SP2, WEBrick. Thanks in advance, Patrick - -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Patrick J. Franz President, Z-Dyne patrick-LkoapWg8zFbQT0dZR+AlfA@public.gmane.org W (408) 230-2340 http://tech.z-dyne.com/index.php -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCSNnunBL/CxPCaScRAicfAJ999r1UaAMbwwruJM/H458OClTkwgCfRUBw fuBwGR0dcN6ehn35A03NmiM=S8c1 -----END PGP SIGNATURE-----
Same thing here. Interestingly, this is just for messages from validates_ helpers, those added by my code in validate() are fine. Validation messages were fine before upgrade to 0.11.1. --------------------- Original message: Hi All-- I have some validations in one of my models: class MyModel < ActiveRecord::Base validates_format_of :zip_code, :with => /\A\d{5}(-\d{4})?\Z/, :message => "Zip code does not match the format of 12345(-6789)." end Now, my controller has ''new'' and ''create'' methods that look like: def new @m = MyModel.new @categories = SomeCategory.find_all end create @m = MyModel.new(@params[''m'']) if @m.save redirect_to :action => ''list'' else @categories = SomeCategory.find_all render_action ''new'' end end Finally, my new.rhtml contains, among other things, [snip] <%= error_messages_for ''m'' %> [snip] When my ''new'' form posts to ''create'' with an invalid zip code, it gets bounced back to ''new'' (as expected), except that it displays the zip code error twice!
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jos wrote:> Same thing here. Interestingly, this is just for messages from > validates_ helpers, those added by my code in validate() are fine. > > Validation messages were fine before upgrade to 0.11.1.I submitted this as ticket #989. If you have anything else to add to it, please do. Thanks, Patrick - -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Patrick J. Franz patrick-LkoapWg8zFbQT0dZR+AlfA@public.gmane.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCSYVhnBL/CxPCaScRAr0tAJwJ+lVYg7vPclYB/88FjZ4BD9SZnQCdGzFk Y6PZVn/AFq8911LB09wDE6Y=eOep -----END PGP SIGNATURE-----
Please see ticket 971: http://dev.rubyonrails.com/ticket/971 This issue is a duplicate. A patch has been attached to that ticket -- feel free to apply it to your development site. I''m waiting for a few people to give it a run with their apps. Please attach your comments to the ticket if you try it out. Even just a "Works for me" comment would be appreciated. Feel free to email me instead if you''d rather not spam trac. -- Nicholas Seckar aka. Ulysses
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Nicholas Seckar wrote:> Please see ticket 971: http://dev.rubyonrails.com/ticket/971 > > This issue is a duplicate. A patch has been attached to that ticket -- feel > free to apply it to your development site. I''m waiting for a few people to > give it a run with their apps. Please attach your comments to the ticket if > you try it out. Even just a "Works for me" comment would be appreciated. Feel > free to email me instead if you''d rather not spam trac.I can''t say that I''ve tested it exhaustively, but the patch does work on my local installation. I added a comment to the ticket and sorry for the duplicate ticket noise. Thanks for the help, Patrick - -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Patrick J. Franz patrick-LkoapWg8zFbQT0dZR+AlfA@public.gmane.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCSlkInBL/CxPCaScRAnsWAJ0d5q7FnjVcmpsi6+0MmDPBu3dauwCfcn1H C7kO9MNgSHehERYgIKaw9L4=XbOn -----END PGP SIGNATURE-----