I have this button which is supposed to update a DIV on the same page (using a partial). But it doesn''t. What am I missing here ?! VIEW: ==== <% form_tag ''/trees'' do -%> <%= submit_to_remote ''new_tree'', ''Add a tree'', :url => { :controller => ''trees'', :action => ''new'' } %> <% end -%> CONTROLLER ========= def new render :update do |page| page.replace_html ''newtree'', :partial => ''user/trees/newtree'' end end Thank you very much for any help! Tom -- 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 -~----------~----~----~----~------~----~------~--~---
Your code seems right. But in case that I havn''t used submit_to_remote, so I cannot tell you what you are missing. Did you use debug to see whether your XMLHttpRequest call can ge caught by the ''new'' action in controller? However I can tell you that using form_remote_tag or defining a button_to_remote using remote_function by yourself can do the trick. On Oct 30, 7:36 am, Tom Ha <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have this button which is supposed to update a DIV on the same page > (using a partial). But it doesn''t. > > What am I missing here ?! > > VIEW: > ====> > <% form_tag ''/trees'' do -%> > <%= submit_to_remote ''new_tree'', ''Add a tree'', :url => { :controller > => ''trees'', :action => ''new'' } %> > <% end -%> > > CONTROLLER > =========> > def new > render :update do |page| > page.replace_html ''newtree'', :partial => ''user/trees/newtree'' > end > end > > Thank you very much for any help! > Tom > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton
2008-Oct-30 01:30 UTC
Re: page.replace_html : How to update a DIV using a button
Hi Tom, Tom Ha wrote:> > I have this button which is supposed to update a DIV > on the same page (using a partial). But it doesn''t. > > What am I missing here ?!Do you have Firebug installed? If not, you definitely need to get that. The console tab is invaluable in debugging Ajax.> > > VIEW: > ====> > <% form_tag ''/trees'' do -%> > <%= submit_to_remote ''new_tree'', ''Add a tree'', :url => { :controller > => ''trees'', :action => ''new'' } %> > <% end -%> >This is interesting. I''m not sure what the impact would be of mixing form_tag, which includes the url (''/trees''), with submit_to_remote, which also includes a url. Especially since they''re different urls in your case (a POST to trees is going to naturally invoke the ''create'' action, not the ''new'' action. You might try just using form_remote_tag instead.> CONTROLLER > =========> > def new > render :update do |page| > page.replace_html ''newtree'', :partial => ''user/trees/newtree''You didn''t show it, so I''ll assume you have a <div id="newtree"> element on the page, and that you have a newtree.rhtml file in views/user/trees/. If either of those is not true, your Ajax definitely won''t work. Bottom line, though, is get Firebug installed in FireFox and see what it''s telling you. HTH, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for your hints! In this case Firebug didn''t throw any error. Sp I replaced: <% form_tag ''/trees'' do -%> <%= submit_to_remote ''new_tree'', ''Add a tree'', :url => { :controller => ''trees'', :action => ''new'' } %> <% end -%> By: <%= button_to_function ''Add a tree'' do |page| page.replace_html ''newtree'', :partial => ''user/trees/newtree'' end %> ...and it works fine! Thanks! Tom -- 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 -~----------~----~----~----~------~----~------~--~---