Hi there how do I pass rails data to a JS array? like arr[0] = @user.name arr[1] = @user.location something like that I''ve been trying differente approaches but no luck so far thanks in advance --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
this works for me in rhtml files: <script type="text/javascript"> name_id=<%= @name.id %>; </script> <script type="text/javascript"> arr[0] = <%= @user.name %> </script> HTH On 9 Mrz., 07:55, "Jorge Mario G. Mazo" <vaders...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi there > how do I pass rails data to a JS array? > like > arr[0] = @user.name > arr[1] = @user.location > > something like that > I''ve been trying differente approaches but no luck so far > thanks in advance--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
to_json is great for this. var user_obj = <%= @user.to_json %>; If you want an array of values: var arr = <%= @user.values.to_json %>; On Mar 9, 2:55 pm, "Jorge Mario G. Mazo" <vaders...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi there > how do I pass rails data to a JS array? > like > arr[0] = @user.name > arr[1] = @user.location > > something like that > I''ve been trying differente approaches but no luck so far > thanks in advance--~--~---------~--~----~------------~-------~--~----~ 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 a lot guys I tried the to_json but for a lame reasson it broke the app webrick wont start On 3/9/07, eden li <eden.li-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > to_json is great for this. > > var user_obj = <%= @user.to_json %>; > > If you want an array of values: > > var arr = <%= @user.values.to_json %>; > > On Mar 9, 2:55 pm, "Jorge Mario G. Mazo" <vaders...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi there > > how do I pass rails data to a JS array? > > like > > arr[0] = @user.name > > arr[1] = @user.location > > > > something like that > > I''ve been trying differente approaches but no luck so far > > thanks in advance > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Weird... can you try: @user.attributes.to_json? What''s in @user? On Mar 10, 7:58 am, "Jorge Mario G. Mazo" <vaders...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks a lot guys > I tried the to_json but for a lame reasson > it broke the app > webrick wont start > > On 3/9/07, eden li <eden...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > to_json is great for this. > > > var user_obj = <%= @user.to_json %>; > > > If you want an array of values: > > > var arr = <%= @user.values.to_json %>; > > > On Mar 9, 2:55 pm, "Jorge Mario G. Mazo" <vaders...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi there > > > how do I pass rails data to a JS array? > > > like > > > arr[0] = @user.name > > > arr[1] = @user.location > > > > something like that > > > I''ve been trying differente approaches but no luck so far > > > thanks in advance--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---