Hi- How to access class variables (@something) within onLoad javascript functions? I pass an array of customers object to a .rhtml file. When it is rendered on the browser, I call an onLoad function. I need to access the @customers objects array in my onLoad function. How can I do that. For example, I need to get to @customers[0][:customer_name] - how to do that? thanks -- 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 -~----------~----~----~----~------~----~------~--~---
Thila Thila wrote:> Hi- > How to access class variables (@something) within onLoad javascript > functions? > > I pass an array of customers object to a .rhtml file. When it is > rendered on the browser, I call an onLoad function. I need to access the > @customers objects array in my onLoad function. How can I do that. For > example, I need to get to @customers[0][:customer_name] - how to do > that? thanksTry something like this in your .rhtml <script> some_var = <%= rails_var %> </script> Then access some_var from onLoad. Topher -- 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 -~----------~----~----~----~------~----~------~--~---
Your only other option would be able to use AJAX to grab the ruby var from the server. Tim -- 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 -~----------~----~----~----~------~----~------~--~---