Johan Sörensen
2005-Mar-24 15:07 UTC
Ajax, validations and oh my god you inputted the wrong values.
First of; big thanks to the Sam and the rest for the javascript helper methods and Prototype, works really well. But one thing still puzzles my mediocre mind: How do I handle validation errors smoothly when someone is posting from a remote_form_tag? Let''s say it looks like this: # view <%= form_remote_tag( :url => { :controller => ''foo'', :action => ''create_with_ajax'' }, :update => ''content_element'', ) %> [some input fields] <%= end_form_tag %> # controller def create_with_ajax @foo = Foo.new(@params["foo"]) if @foo.save? @foos = Foo.find_all render "bar/list_foos" else # validation failed, now what? end end I''m guessing I can''t redirect to a "standard create view", since that would destroy my errors? And rendering the errors in the content_element isn''t particular nice, so I''m not quite sure what to do? What I''m looking for is really a kind of "best practices" when it comes to validations and ajax powered forms. -- johan
Lee Pope
2005-May-25 15:53 UTC
Re: Ajax, validations and oh my god you inputted the wrong values.
Johan -- I''m really bummed you haven''t gotten a better response here -- this seems to be a key issue, and there are some *really* sharp people working on this. I hope this problem gets some attention -- i have struggled with it for a while, and haven''t got anything profound to contribute, other than to kick this thread. lee On 3/24/05, Johan Sörensen <johans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> First of; big thanks to the Sam and the rest for the javascript helper > methods and Prototype, works really well. > > But one thing still puzzles my mediocre mind: How do I handle > validation errors smoothly when someone is posting from a > remote_form_tag? > > Let''s say it looks like this: > # view > <%= form_remote_tag( > :url => { :controller => ''foo'', :action => > ''create_with_ajax'' }, > :update => ''content_element'', > ) %> > [some input fields] > <%= end_form_tag %> > > # controller > def create_with_ajax > @foo = Foo.new(@params["foo"]) > if @foo.save? > @foos = Foo.find_all > render "bar/list_foos" > else > # validation failed, now what? > end > end > > I''m guessing I can''t redirect to a "standard create view", since that > would destroy my errors? And rendering the errors in the > content_element isn''t particular nice, so I''m not quite sure what to > do? > What I''m looking for is really a kind of "best practices" when it > comes to validations and ajax powered forms. > > -- johan > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Chris Boone
2005-May-25 21:53 UTC
Re: Ajax, validations and oh my god you inputted the wrong values.
I haven''t tried this, so please correct me if I''m off base, but couldn''t you put @errors into the flash, redirect to your standard view, then pull @errors back out and deal with it there? On 5/25/05, Lee Pope <leepope-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Johan -- > > I''m really bummed you haven''t gotten a better response here -- this > seems to be a key issue, and there are some *really* sharp people > working on this. I hope this problem gets some attention -- i have > struggled with it for a while, and haven''t got anything profound to > contribute, other than to kick this thread. > > lee > > On 3/24/05, Johan Sörensen <johans-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > First of; big thanks to the Sam and the rest for the javascript helper > > methods and Prototype, works really well. > > > > But one thing still puzzles my mediocre mind: How do I handle > > validation errors smoothly when someone is posting from a > > remote_form_tag? > > > > Let''s say it looks like this: > > # view > > <%= form_remote_tag( > > :url => { :controller => ''foo'', :action => > > ''create_with_ajax'' }, > > :update => ''content_element'', > > ) %> > > [some input fields] > > <%= end_form_tag %> > > > > # controller > > def create_with_ajax > > @foo = Foo.new(@params["foo"]) > > if @foo.save? > > @foos = Foo.find_all > > render "bar/list_foos" > > else > > # validation failed, now what? > > end > > end > > > > I''m guessing I can''t redirect to a "standard create view", since that > > would destroy my errors? And rendering the errors in the > > content_element isn''t particular nice, so I''m not quite sure what to > > do? > > What I''m looking for is really a kind of "best practices" when it > > comes to validations and ajax powered forms. > > > > -- johan > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Chris Boone http://hypsometry.com/ : website edification http://uvlist.org/ : free classifieds for the Upper Valley
Rick Olson
2005-May-25 22:01 UTC
Re: Ajax, validations and oh my god you inputted the wrong values.
On 5/25/05, Chris Boone <hypsometry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I haven''t tried this, so please correct me if I''m off base, but > couldn''t you put @errors into the flash, redirect to your standard > view, then pull @errors back out and deal with it there?Another option would be to serialize the @errors into a JSON construct, pass that to the ajax, and have it do something meaningful with it. The redirection method would be much simpler though. -- rick http://techno-weenie.net