For a regular form I use the :onlick option to disable the submit button after the first click in order to prevent double clicks (leading to double entries): <% form_tag :action => ''create'' do %> <%= submit_tag "Create", :onclick => "this.disabled=true,this.form.submit();"%> I''m having trouble using this same method to prevent double clicks in an ajax form: <% form_remote_tag :url => {:action => ''enter_payment''} do %> <%= submit_tag ''Enter'', :onclick => "this.disabled=true,this.form.submit();" %> This controller method ''enter_payment'' for this ajax form creates an object and re-renders a couple partials. With this code, the object is created, but the following error comes up when it tries to render the partials: "Can only render or redirect once per action" When I comment one of the partials out, it redirects to the other partial instead of re-rendering it within the original page. How might I be able to fix this? Thanks, Peter -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2007-Dec-04 17:38 UTC
Re: Problem preventing double click with ajax submit button
how about posting the controller code, where the error appears? -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Marks
2007-Dec-04 17:53 UTC
Re: Problem preventing double click with ajax submit button
Here''s the controller code. It works fine without the onclick option in the submit button (renders the partials without reloading the page). I''m guessing the submit method I''m using in the :onclick option is expecting a redirect. That would explain it redirecting me to a partial and it failing when it gets multiple redirect commands. I''m pretty javascript retarded though. I just hack what I see and hope it works :/ def input @person = Person.find(params[:id]) name = (params[:name]) if @person.update_attributes(params[:person]) event = Event.create(:person_id => @person.id, :name => name, :date => Time.now) @new_event = event return if request.xhr? render :partial => ''events'' render :partial => ''inputs'' end end Thanks again for having a look at this Thorsten. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2007-Dec-04 18:12 UTC
Re: Problem preventing double click with ajax submit button
my guess would be, that return if request.xhr? prevents the trouble for non-ajax by simply returning and never reaching the render calls make something like logger.info("foo") to see, if it reaches the lines at all anyway, the error message is right, since two render calls are not allowed and if the partials do not contain rjs, that will fail and render the whole partial as a page. one reason, there''s nowhere any information, which html-tag to replace or use as target one option would be: <% form_remote_tag :url => {:action => ''enter_payment''}, :update => ''my_html_id'' do %> not exactly, what i would prefer, which would be more like render :update do |page| page.replace "my_html_id_1", :partial => "events" page.replace "my_html_id_2", :partial => "inputs" end in this case, without changes to your view code -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Marks
2007-Dec-04 18:22 UTC
Re: Problem preventing double click with ajax submit button
Thanks for the ideas. I get a different, but still incorrect result when I submit to a method with inline rjs like you''re suggesting. It redirects the browser to the controller method but, instead of rendering the partial, it renders code for the javascript instructions. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2007-Dec-04 18:29 UTC
Re: Problem preventing double click with ajax submit button
Peter Marks wrote:> Thanks for the ideas. I get a different, but still incorrect result when > I submit to a method with inline rjs like you''re suggesting. It > redirects the browser to the controller method but, instead of rendering > the partial, it renders code for the javascript instructions.that one... :) somehow it''s loosing the information, that''s an ajax call and handles the returned text as html i had some trouble with remote forms and manually calling submit, maybe you can hack around it with calling onsubmit instead or test it with link_to_remote, until you get working code, without additional trouble of form-submit and remember, not to use :update =>, but your code: <% form_remote_tag :url => {:action => ''enter_payment''} do %> in the view -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Marks
2007-Dec-04 18:31 UTC
Re: Problem preventing double click with ajax submit button
Thorsten Mueller wrote:> that one... :) > > somehow it''s loosing the information, that''s an ajax call and handles > the returned text as html > > i had some trouble with remote forms and manually calling submit, maybe > you can hack around it with calling onsubmit instead > > or test it with link_to_remote, until you get working code, without > additional trouble of form-submit > > and remember, not to use :update =>, but your code: > <% form_remote_tag :url => {:action => ''enter_payment''} do %> > in the viewWell I''m glad I''m not the only one having trouble with this :) Thanks again Thorsten. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---