I have such a code in my "create" method: respond_to do |format| if user.save() format.html {redirect_to(:action => "show")} else format.js end end So if save() is successful I want full redirect to a different page. If not successful then no redirect, just show user an ajax message about the error on the same page. My form is with ''data-remote="true"''. And my "create.js.erb" is simple: document.getElementById("warn").innerHTML = "<p>Error</p>"; Save() works fine but I get no redirection. The same page stays without change. And if save() is impossible then format.js works fine. But why redirection doesn''t work? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-Apr-17 01:27 UTC
Re: Conditional respond_to doesn''t do redirect
On Tue, Apr 16, 2013 at 7:15 PM, Wins Lin <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have such a code in my "create" method: > > respond_to do |format| > if user.save() > format.html {redirect_to(:action => "show")} > else > format.js > end > end > > So if save() is successful I want full redirect to a different page. If > not successful then no redirect, just show user an ajax message about > the error on the same page. > > My form is with ''data-remote="true"''. > > And my "create.js.erb" is simple: > document.getElementById("warn").innerHTML = "<p>Error</p>"; > > > Save() works fine but I get no redirection. The same page stays without > change. And if save() is impossible then format.js works fine. But why > redirection doesn''t work?If this is responding to an AJAX request, what do you think would be the result of redirecting the AJAX request? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists wrote in post #1105944:> > If this is responding to an AJAX request, what do you think would be > the result of redirecting the AJAX request?Yes, you''re right :) window.location = ... works -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.