From: "Kai König" Date: 2010-05-16T20:30:10+09:00 Subject: Re: Accessing elements of a ruby array with javascript You cant access the ruby array from javascript because it gets executed by two different interpreters of which both dont know the state of the other and therefor can not access the other's variables , but you could do something like this var js_array = [<= @ruby_arrray.map{|i| "\"#{i}\""}.join(",")] // results into a valid Javascript Array of Strings which gets parsed by JS for(;;){ var title = js_array[i] } /* Or you could fetch the events from server, if your task involves web- development */ // on the client var my_obj = {} jQuery.getJSON("/some/where/on/your/server.json",function(data){ my_obj = data; // Data now contains all you events. }); // on the server something like this: def server @events = Event.find(:all) render :json => @events.to_json end You also seem to be new to web-development and i suppose you make your self familiar with the topic/technologie through some books. On 16.05.2010, at 02:45, Brandon Jake12jake wrote: > So I'm very new to both ruby and javascript, but the basic problem > is. I > have a ruby array @events_this_month, and i'm running a javascript > loop > that basically needs the information from this array. The problem is I > can't seem to set the proper index for my ruby array. What I have > looks > like this: > > > for( var i = 0; i < 3; i++) > { > var title = '<%= @events_this_month[i].title %>'; > alert(title); > } > > I've also tried: > > <%= $j = 0 %> > for( var i = 0; i < 3; i++) > { > var title = '<%= @events_this_month[$j].title %>'; > alert('<%= $j %>'); > <%= $j = $j +1 %> > } > > Any suggestions on how I can access the correct index in my ruby array > during the javascript loop? > -- > Posted via http://www.ruby-forum.com/. >