Hi, I''ve been looking around on the forums and tutorials but I still can''t seem to make this work. Here is what I am trying to do. I have a view do a form_remote_tag with some variables. In the controller I want to create an array, fill it with values, and when the function returns I want to call a javascript function with this array. currently this is what I have that doesn''t work ******** view ******* <script type="text/javascript"> function javascript_functionA(items){ //do things with items } </script> <% form_remote_tag :complete => "javascript_functionA(''#{myArray}''), :url => {:action => :controller_functionA} %> ******** controller ******* class MyController < ApplicationController def controller_functionA myArray = ["so", "many", "exciting", "things"] end end I know I must be doing something wrong but being new to rails there just seems like to many places where I could be messing things up. Thanks for the help, Lee -- 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 -~----------~----~----~----~------~----~------~--~---
Lee Thompson wrote:> > Hi, > > I''ve been looking around on the forums and tutorials but I still can''t > seem to make this work. > > Here is what I am trying to do. > I have a view do a form_remote_tag with some variables. In the > controller I want to create an array, fill it with values, and when the > function returns I want to call a javascript function with this array. > > currently this is what I have that doesn''t work > ******** view ******* > <script type="text/javascript"> > function javascript_functionA(items){ > //do things with items > } > </script> > <% form_remote_tag :complete => "javascript_functionA(''#{myArray}''), > :url => {:action => :controller_functionA} %> > > ******** controller ******* > class MyController < ApplicationController > def controller_functionA > myArray = ["so", "many", "exciting", "things"] > end > end >I don''t know what parameters are valid for javascript_functionA(), but it may be expecting (''value1'', ''value2'', ... ). Looks like ''#{myArray}'' is giving just one parameter (''value1''). You may have to reference each array value by its indices. Long --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Long wrote:> Lee Thompson wrote: >> >> ******** controller ******* >> class MyController < ApplicationController >> def controller_functionA >> myArray = ["so", "many", "exciting", "things"] >> end >> end >> > I don''t know what parameters are valid for javascript_functionA(), but > it > may be expecting (''value1'', ''value2'', ... ). Looks like ''#{myArray}'' is > giving > just one parameter (''value1''). > > You may have to reference each array value by its indices. > > LongThanks for the response Long, You might be right about that.. but for now I actually get this error undefined local variable or method `myArray'' for #<#<Class:0x409c9ec4>:0x409c9e9c> The array never makes it to the javascript_functionA the MyController creates myArray, but the view has no idea about it. -- 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 -~----------~----~----~----~------~----~------~--~---
Lee Thompson wrote:> > Long wrote: > > Lee Thompson wrote: > >> > >> ******** controller ******* > >> class MyController < ApplicationController > >> def controller_functionA > >> myArray = ["so", "many", "exciting", "things"] > >> end > >> end > >> > > I don''t know what parameters are valid for javascript_functionA(), but > > it > > may be expecting (''value1'', ''value2'', ... ). Looks like ''#{myArray}'' is > > giving > > just one parameter (''value1''). > > > > You may have to reference each array value by its indices. > > > > Long > > Thanks for the response Long, > > You might be right about that.. but for now I actually get this error > undefined local variable or method `myArray'' for > #<#<Class:0x409c9ec4>:0x409c9e9c> > > The array never makes it to the javascript_functionA > > the MyController creates myArray, but the view has no idea about it. >Right, try make myArray an instance variable (@myArray) instead of a local variable. Then reference @myArray in your view instead of myArray. Long --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---