If I have a form that submits via Ajax, is there a way to specify that I don''t want to update anything after the call can been made? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
You can''t necessarily get AJAX to redirect to another page but, you could do something like: def ajax_action if we_need_to_redirect render_text "window.location.href = ''http://host.com/path/to/file'';" end end then, when you call the AJAX request: <%= form_remote_tag :url => {:action => "ajax_action"}, :complete => "eval(request.responseText);" %> ________________________________ From: Colin Ramsay [mailto:colinramsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] Sent: Saturday, 9 July 2005 8:15 PM To: Wayne Robinson Subject: Re: [Rails] form_tag_remote and :update Oh. For some reason I had assumed it was compulsory! While we''re here, another question. Normally the point of an Ajax call is to prevent having to do a postback. What if, under certain circumstances (for example I have just deleted my last record) I would like my Ajax call to redirect to another page? Is that possible? On 7/9/05, Wayne Robinson <wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: Don''t use :update in the function call e.g. form_remote_tag :url => {:action => "do_something"} ________________________________ From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Colin Ramsay Sent: Saturday, 9 July 2005 8:01 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] form_tag_remote and :update If I have a form that submits via Ajax, is there a way to specify that I don''t want to update anything after the call can been made? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Good plan. Thanks. On 7/9/05, Wayne Robinson <wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote:> > You can''t necessarily get AJAX to redirect to another page but, you could > do something like: > > def ajax_action > > if we_need_to_redirect > > render_text "window.location.href = ''http://host.com/path/to/file'';" > > end > > end > > then, when you call the AJAX request: > > <%= form_remote_tag :url => {:action => "ajax_action"}, :complete => > "eval(request.responseText);" %> > > ------------------------------ > > *From:* Colin Ramsay [mailto:colinramsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] > *Sent:* Saturday, 9 July 2005 8:15 PM > *To:* Wayne Robinson > *Subject:* Re: [Rails] form_tag_remote and :update > > Oh. For some reason I had assumed it was compulsory! While we''re here, > another question. Normally the point of an Ajax call is to prevent having to > do a postback. What if, under certain circumstances (for example I have just > deleted my last record) I would like my Ajax call to redirect to another > page? > > Is that possible? > > On 7/9/05, *Wayne Robinson* <wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: > > Don''t use :update in the function call > > e.g. form_remote_tag :url => {:action => "do_something"} > > ------------------------------ > > *From:* rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto: > rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of *Colin Ramsay > *Sent:* Saturday, 9 July 2005 8:01 PM > *To:* rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* [Rails] form_tag_remote and :update > > If I have a form that submits via Ajax, is there a way to specify that I > don''t want to update anything after the call can been made? > > > _______________________________________________ > 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
Cool, I wasn''t aware of that (obviously). -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Thomas Fuchs Sent: Saturday, 9 July 2005 9:23 PM To: Colin Ramsay; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] form_tag_remote and :update or, with 0.13.0: <%= form_remote_tag :url => {:action => "ajax_action"}, :complete => evaluate_remote_resonse %> Thomas Am 09.07.2005 um 12:21 schrieb Colin Ramsay:> Good plan. Thanks. > > On 7/9/05, Wayne Robinson <wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: > You can''t necessarily get AJAX to redirect to another page but, you > could do something like: > > > def ajax_action > > if we_need_to_redirect > > render_text "window.location.href = ''http://host.com/path/to/ > file'';" > > end > > end > > > then, when you call the AJAX request: > > > <%= form_remote_tag :url => {:action => "ajax_action"}, :complete > => "eval(request.responseText);" %> > > > From: Colin Ramsay [mailto:colinramsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] > Sent: Saturday, 9 July 2005 8:15 PM > To: Wayne Robinson > Subject: Re: [Rails] form_tag_remote and :update > > > Oh. For some reason I had assumed it was compulsory! While we''re > here, another question. Normally the point of an Ajax call is to > prevent having to do a postback. What if, under certain > circumstances (for example I have just deleted my last record) I > would like my Ajax call to redirect to another page? > > Is that possible? > > On 7/9/05, Wayne Robinson < wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: > > Don''t use :update in the function call > > e.g. form_remote_tag :url => {:action => "do_something"} > > > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails- > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Colin Ramsay > Sent: Saturday, 9 July 2005 8:01 PM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails] form_tag_remote and :update > > > If I have a form that submits via Ajax, is there a way to specify > that I don''t want to update anything after the call can been made? > > > > _______________________________________________ > 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 >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
or, with 0.13.0: <%= form_remote_tag :url => {:action => "ajax_action"}, :complete => evaluate_remote_resonse %> Thomas Am 09.07.2005 um 12:21 schrieb Colin Ramsay:> Good plan. Thanks. > > On 7/9/05, Wayne Robinson <wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: > You can''t necessarily get AJAX to redirect to another page but, you > could do something like: > > > def ajax_action > > if we_need_to_redirect > > render_text "window.location.href = ''http://host.com/path/to/ > file'';" > > end > > end > > > then, when you call the AJAX request: > > > <%= form_remote_tag :url => {:action => "ajax_action"}, :complete > => "eval(request.responseText);" %> > > > From: Colin Ramsay [mailto:colinramsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] > Sent: Saturday, 9 July 2005 8:15 PM > To: Wayne Robinson > Subject: Re: [Rails] form_tag_remote and :update > > > Oh. For some reason I had assumed it was compulsory! While we''re > here, another question. Normally the point of an Ajax call is to > prevent having to do a postback. What if, under certain > circumstances (for example I have just deleted my last record) I > would like my Ajax call to redirect to another page? > > Is that possible? > > On 7/9/05, Wayne Robinson < wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: > > Don''t use :update in the function call > > e.g. form_remote_tag :url => {:action => "do_something"} > > > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails- > bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Colin Ramsay > Sent: Saturday, 9 July 2005 8:01 PM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails] form_tag_remote and :update > > > If I have a form that submits via Ajax, is there a way to specify > that I don''t want to update anything after the call can been made? > > > > _______________________________________________ > 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 >
should be :complete => evaluate_remote_response obviously :) also, have a look at the new update_element_function helper! Thomas Am 09.07.2005 um 13:20 schrieb Wayne Robinson:> Cool, I wasn''t aware of that (obviously). > > -----Original Message----- > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Thomas Fuchs > Sent: Saturday, 9 July 2005 9:23 PM > To: Colin Ramsay; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails] form_tag_remote and :update > > or, with 0.13.0: > > <%= form_remote_tag :url => {:action => "ajax_action"}, :complete => > evaluate_remote_resonse %> > > Thomas > > Am 09.07.2005 um 12:21 schrieb Colin Ramsay: > > >> Good plan. Thanks. >> >> On 7/9/05, Wayne Robinson <wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: >> You can''t necessarily get AJAX to redirect to another page but, you >> could do something like: >> >> >> def ajax_action >> >> if we_need_to_redirect >> >> render_text "window.location.href = ''http://host.com/path/to/ >> file'';" >> >> end >> >> end >> >> >> then, when you call the AJAX request: >> >> >> <%= form_remote_tag :url => {:action => "ajax_action"}, :complete >> => "eval(request.responseText);" %> >> >> >> From: Colin Ramsay [mailto:colinramsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] >> Sent: Saturday, 9 July 2005 8:15 PM >> To: Wayne Robinson >> Subject: Re: [Rails] form_tag_remote and :update >> >> >> Oh. For some reason I had assumed it was compulsory! While we''re >> here, another question. Normally the point of an Ajax call is to >> prevent having to do a postback. What if, under certain >> circumstances (for example I have just deleted my last record) I >> would like my Ajax call to redirect to another page? >> >> Is that possible? >> >> On 7/9/05, Wayne Robinson < wayner-WE50rThZ+ga6c6uEtOJ/EA@public.gmane.org> wrote: >> >> Don''t use :update in the function call >> >> e.g. form_remote_tag :url => {:action => "do_something"} >> >> >> From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails- >> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Colin Ramsay >> Sent: Saturday, 9 July 2005 8:01 PM >> To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> Subject: [Rails] form_tag_remote and :update >> >> >> If I have a form that submits via Ajax, is there a way to specify >> that I don''t want to update anything after the call can been made? >> >> >> >> _______________________________________________ >> 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 >> >> > > _______________________________________________ > 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 >
On 7/9/05, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote:> also, have a look at the new update_element_function helper!Would be valid to embed a call to another template via render_partial like so? <%= update_element_function("c#{item.context_id}", :position => :bottom) do %> render_partial( ''show_item'', item ) <% end %> Is _show_item.rhtml returning both html and javascript (AJAX code) going to cause problems? -- Nicholas Lee http://stateless.geek.nz gpg 8072 4F86 EDCD 4FC1 18EF 5BDD 07B0 9597 6D58 D70C
I use it like this: <%= update_element_function("c#{item.context_id}", :position => :bottom, :content => render(...)) %> If you want to mix HTML and JS, you need to: 1. don''t use :complete => evaluate_remote_response 2. wrap the calls to update_element_function in javascript_tag calls: <%= javascript_tag(update_element_function(...)) %> See the RDoc for update_element_function for some examples: http://api.rubyonrails.com/classes/ActionView/Helpers/ JavaScriptHelper.html Thomas Am 09.07.2005 um 15:19 schrieb Nicholas Lee:> On 7/9/05, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote: > > >> also, have a look at the new update_element_function helper! >> > > Would be valid to embed a call to another template via > render_partial like so? > > <%= update_element_function("c#{item.context_id}", :position > => :bottom) do %> > render_partial( ''show_item'', item ) > <% end %> > > Is _show_item.rhtml returning both html and javascript (AJAX code) > going to cause problems? > > -- > Nicholas Lee > http://stateless.geek.nz > gpg 8072 4F86 EDCD 4FC1 18EF 5BDD 07B0 9597 6D58 D70C > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 7/9/05, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote:> I use it like this: > > <%= update_element_function("c#{item.context_id}", :position > => :bottom, :content => render(...)) %> > > If you want to mix HTML and JS, you need to: > > 1. don''t use :complete => evaluate_remote_responseThen how do you get the javascript/html returned by the XHTML response with form_remote_tag to be processed by the page?> 2. wrap the calls to update_element_function in javascript_tag calls: > > <%= javascript_tag(update_element_function(...)) %> > > See the RDoc for update_element_function for some examples: > http://api.rubyonrails.com/classes/ActionView/Helpers/ > JavaScriptHelper.htmlDoes this only work in page/view and work from form_remote_tag (another controller/action)? Thanks. -- Nicholas Lee http://stateless.geek.nz gpg 8072 4F86 EDCD 4FC1 18EF 5BDD 07B0 9597 6D58 D70C