So here is my view: CODE: <%= link_to_remote("replace1", :update => ''replaceMe'', :url => { :action => :hello_world }) %> <%= link_to_remote("replace2", :update => ''replaceMe2'', :url => { :action => :goodbye_world }) %> <div id="replaceMe">replace me</div> <div id="replaceMe2">replace me also</div> END When i click the "replace1" link - the replaceMe div is replaced with the content of the hello_world action. When i click the "replace2" link - the replaceMe2 div is replaced with the content of the goodbye_world action. What i really want, though, is to have one link (''replace both'') that will replace both divs with their new content. How can i do this? Lindsay
Hi Lindsay, I am new to Rails, so there may be a way to do what you are asking. But as an alternative, couldn''t you just have one area that both of those links replace, sort of like: <div id="replaceMe"> <div id="thing1">Thing 1</div> <div id="thing2">Thing 2</div> </div> Your replace text would have to contain both elements... but it seems easier to manage and think about than trying to replace two things separately but at the same time. A method call could just return the thing1 and thing 2 div tags with the new content in them. If that will not work for you, then hopefully someone else will respond :) Tom On 7/14/05, Lindsay <hellolindsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So here is my view: > > CODE: > > <%= link_to_remote("replace1", > :update => ''replaceMe'', > :url => { :action => :hello_world }) %> > > <%= link_to_remote("replace2", > :update => ''replaceMe2'', > :url => { :action => :goodbye_world }) %> > > <div id="replaceMe">replace me</div> > > <div id="replaceMe2">replace me also</div> > > END > > When i click the "replace1" link - the replaceMe div is replaced with > the content of the hello_world action. > When i click the "replace2" link - the replaceMe2 div is replaced with > the content of the goodbye_world action. > > What i really want, though, is to have one link (''replace both'') that > will replace both divs with their new content. > > How can i do this? > > Lindsay > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks tom - but i''m actually looking for a solution that will work in any situation regardless of the number or location of the divs. Since i havn''t gotten any other responses i will post the half-solution i am using for now. - - - HALF-SOLUTION (it works): This code: <%= link_to_remote("replace1", :update => ''replaceMe'', :url => { :action => :hello_world }) %> renders like this: <a href="#" onclick="new Ajax.Updater(''replace1'', ''/entrance/hello_world'', {asynchronous:true, evalScripts:true}); return false;">replace1</a> Notice that the first two parameters being passed to the Ajax.Updater object are the div''s id, and the path to the action. So.... If i want to update two divs i can just duplicate the function call, and change those values - like this: <a href="#" onclick="new Ajax.Updater(''replace1'', ''/entrance/hello_world'', {asynchronous:true, evalScripts:true}); new Ajax.Updater(''replace2'', ''/entrance/goodbye_world'', {asynchronous:true, evalScripts:true}); return false;">replace both</a> This is ugly though, because i have to hard-code the anchor tag into a template. - - - BETTER (non-existant-i-think) SOLUTION: If there was a function similar to link_to_remote that returned the ''new Ajax.Updater(...)'' script without the surrounding anchor tag (lets call it ajax_update) then i could do something like this: <% link_to_function "replace both", "#{ajax_update(:id => ''replace1'', :action =>''hello_world''};#{ajax_update(:id => ''replace2'', :action => ''goodbye_world'')};" %> - - - EVEN BETTER (non-existant-i-think) SOLUTION: Just upgrade the link_to_remote function: <% link_to_remote "replace both", { :update => "replace1", :action => "hello_world" }, { :update => "replace2, :action => "goodbye_world} %> Does anyone have any other thoughts are comments on this? Are either to the non-existant-i-think solutions currently possible? Is anything like this going to be added to rails in the future? Lindsay On 7/14/05, Tom Davies <atomgiant-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Lindsay, > > I am new to Rails, so there may be a way to do what you are asking. > But as an alternative, couldn''t you just have one area that both of > those links replace, sort of like: > > <div id="replaceMe"> > <div id="thing1">Thing 1</div> > <div id="thing2">Thing 2</div> > </div> > > Your replace text would have to contain both elements... but it seems > easier to manage and think about than trying to replace two things > separately but at the same time. A method call could just return the > thing1 and thing 2 div tags with the new content in them. > > If that will not work for you, then hopefully someone else will respond :) > > Tom > > On 7/14/05, Lindsay <hellolindsay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > So here is my view: > > > > CODE: > > > > <%= link_to_remote("replace1", > > :update => ''replaceMe'', > > :url => { :action => :hello_world }) %> > > > > <%= link_to_remote("replace2", > > :update => ''replaceMe2'', > > :url => { :action => :goodbye_world }) %> > > > > <div id="replaceMe">replace me</div> > > > > <div id="replaceMe2">replace me also</div> > > > > END > > > > When i click the "replace1" link - the replaceMe div is replaced with > > the content of the hello_world action. > > When i click the "replace2" link - the replaceMe2 div is replaced with > > the content of the goodbye_world action. > > > > What i really want, though, is to have one link (''replace both'') that > > will replace both divs with their new content. > > > > How can i do this? > > > > Lindsay > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
You can call the (undocumented) helper method remote_function to generate AJAX calls like this: <a href="#" onclick="<%= remote_function(:update => ''replaceMe'', :url => { :action => :hello_world })%>;<%= remote_function(:update => ''replaceSomethingElse'', :url => { :action => :hello_moon })%>;return false;">linktext</a> Note that that will issue two simultanously executed AJAX calls - no way to call two URLs with just one call :) Thomas> This code: > > <%= link_to_remote("replace1", > :update => ''replaceMe'', > :url => { :action => :hello_world }) %> > > renders like this: > > <a href="#" onclick="new Ajax.Updater(''replace1'', > ''/entrance/hello_world'', {asynchronous:true, evalScripts:true}); > return false;">replace1</a>
Just what I was looking for, schweet. Thanks, PJ On 7/14/05, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote:> You can call the (undocumented) helper method remote_function to > generate AJAX calls like this: > > <a href="#" onclick="<%= remote_function(:update => ''replaceMe'', :url > => { :action => :hello_world })%>;<%= remote_function(:update => > ''replaceSomethingElse'', :url => { :action => :hello_moon })%>;return > false;">linktext</a> > > Note that that will issue two simultanously executed AJAX calls - no > way to call two URLs with just one call :) > > Thomas > > > > This code: > > > > <%= link_to_remote("replace1", > > :update => ''replaceMe'', > > :url => { :action => :hello_world }) %> > > > > renders like this: > > > > <a href="#" onclick="new Ajax.Updater(''replace1'', > > ''/entrance/hello_world'', {asynchronous:true, evalScripts:true}); > > return false;">replace1</a> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Yup - that''s exactly what i wanted :) Many thanks to you and your bretheren. Lindsay On 7/14/05, PJ Hyett <pjhyett-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just what I was looking for, schweet. > > Thanks, > PJ > > On 7/14/05, Thomas Fuchs <thomas-9D208sng4xU@public.gmane.org> wrote: > > You can call the (undocumented) helper method remote_function to > > generate AJAX calls like this: > > > > <a href="#" onclick="<%= remote_function(:update => ''replaceMe'', :url > > => { :action => :hello_world })%>;<%= remote_function(:update => > > ''replaceSomethingElse'', :url => { :action => :hello_moon })%>;return > > false;">linktext</a> > > > > Note that that will issue two simultanously executed AJAX calls - no > > way to call two URLs with just one call :) > > > > Thomas > > > > > > > This code: > > > > > > <%= link_to_remote("replace1", > > > :update => ''replaceMe'', > > > :url => { :action => :hello_world }) %> > > > > > > renders like this: > > > > > > <a href="#" onclick="new Ajax.Updater(''replace1'', > > > ''/entrance/hello_world'', {asynchronous:true, evalScripts:true}); > > > return false;">replace1</a> > > _______________________________________________ > > 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 >