The effect I''m trying to achieve here is basically as follows: test_controller.rb ---------------- class TestController < ApplicationController def test end def fetch @array = [1,2,3,4,5,6,7,8,9] end end fetch.rhtml ------------ <p>TEST<p> <%= x=0 %> <script> for (var i=0; i<10; i++) { document.write("Test - " <%= @array[x]; x+=1 %>); } </script> And this would generate the output of.. Test - 1 Test - 2 Test - 3 ect. However it fails miserably :( Instead it just prints Test - 1 10 times, so its basically interpreting the x+=1 wrong. Any suggestions are much appreciated, Thanks, - Jon -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 30, 6:48 am, Michael Linfield <rails-mailing-l...@andreas- s.net> wrote:> fetch.rhtml > ------------ > > <p>TEST<p> > <%= x=0 %> > <script> > > for (var i=0; i<10; i++) { > document.write("Test - " <%= @array[x]; x+=1 %>); > } > > </script> >There is no ruby iteration here (ie this chunk of view executes from top to bottom with no looping, ie it''s not the x+=1 going wrong. just that from ruby''s point of view there is no loop. You either need to make that array exist in javascript land and then just iterate through it in javascript or do the iteration in your view itself (ie something like <% @array.each do |value| %> document.write("Test - <%=value%>") <% end %> Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---