Lille
2010-May-25 17:01 UTC
how to handle remote_form_tag post either by i) ajax or ii) redirection
Hi, I have non-model custom validation for a data input to a certain remote_form_tag view. I''d like to have differential responses in the controller in the following cases: 1) when remote_form_tag post results fail validation, the form view is updated from the controller, as by the following: render :update do |page| page.replace_html ''errors'', :partial => "iod_errors" end 2) when the remote_form_tag post results passes validation, the controller redirects to another action or view, as in the following: redirect_to passed_validation_url Unfortunately, using the following simple parameterization of form_remote_tag, <% form_remote_tag :url=>create_iod_url do %> ... I am succesful in my case 1), but nothing happens at all in my case 2). Any suggestions? Thanks, Lille -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-May-25 17:07 UTC
Re: how to handle remote_form_tag post either by i) ajax or ii) redirection
On May 25, 6:01 pm, Lille <lille.pengu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am succesful in my case 1), but nothing happens at all in my case > 2).If your form is expecting rjs then you need to give it rjs (eg page.redirect_to). Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lille
2010-May-25 17:23 UTC
Re: how to handle remote_form_tag post either by i) ajax or ii) redirection
Fred, Thanks, that worked great. I don''t understand why the form is expecting anything after it has submitted to the controller, i.e., I don''t understand that a remote_form_tag handles redirect_to calls. Maybe I don''t get where RJS is ''taking place''. For the record the solution snippet sequence is as follows: [controller action: case 1] render :update do |page| page.replace_html ''errors'', :partial => "iod_errors" end [controller action: case 2] render :update do |page| page.redirect_to passed_validation_url end [form_remote_tag] <% form_remote_tag :url=>create_iod_url do %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-May-25 17:46 UTC
Re: how to handle remote_form_tag post either by i) ajax or ii) redirection
On May 25, 6:23 pm, Lille <lille.pengu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Fred, > > Thanks, that worked great. > > I don''t understand why the form is expecting anything after it has > submitted to the controller, i.e., I don''t understand that a > remote_form_tag handles redirect_to calls. Maybe I don''t get where RJS > is ''taking place''.What rjs means is that a response consisting entirely of javascript is generated. Ajax requests in prototype come in two flavours: Either they expect to get a fragment of html back which they insert into a specific place in the DOM or they expect to get some javascript back in which case they execute it. Stuff like link_to_remote and remote_form_for will create the former (Ajax.Updater) if you supply an :update option (the id of the element to update) and an Ajax.Request if not Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.