I want to make a call to remote_function with 1 of the parameters derived from a javascript call. For example: <%= remote_function(:url => {:action = "xyz", :id => getId()}, :update => ''main_content'') %> getId() is a Javascript function. Can something like this be done? Conversely, can the remote_function(options) call be made from javascript. Something like def f() { var options = {"url": {"action": "xyz", "id" : getId()}, "update": "main_content"}; remote_function(options); } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-29 08:38 UTC
Re: Can Javascript code be called from with <%= %> tags.
On 28 May 2008, at 23:36, JeffB wrote:> > I want to make a call to remote_function with 1 of the parameters > derived from a javascript call. > > For example: > <%= remote_function(:url => {:action = "xyz", :id => getId()}, :update > => ''main_content'') %> > > getId() is a Javascript function. > > Can something like this be done? >Yes and no. The javascript clearly cannot be evaluated at the time that the <%= is evaluated, since that happens server side. However, the remote_function family do take a :with option, which is a string of javascript to be executed and bashed into the parameters when the ajax call is made. I wrote up some of the ways of playing with the :with option at http://www.spacevatican.org/2008/5/17/with-or-without-you-link_to_remote-s-mysterious-parameter> > Conversely, > can the remote_function(options) call be made from javascript. >remote_function just generates some javascript, usually something like new Ajax.Updater(''some_div'', /foo/bar, {some: options} Fred> Something like > def f() > { > var options = {"url": {"action": "xyz", "id" : getId()}, "update": > "main_content"}; > remote_function(options); > } > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---