yourvishonline-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-15 06:10 UTC
Help on sending an array in ruby to javascript method
hi all,
I am new to ruby on rails and doing a small application as I am
learning ruby on rails..
Problem:
Basically I want to send an array @all_languages to a javascript method
..... and be able to access the array in it...
Details:
I have an array of (language_name,language_id) pairs in variable
@all_languages
Eg: [ ( English, 1 ) , ( French, 2 ) , ( German, 3 ) ] ...
I am displaying every language as a row in a table
I have a link called add_lang_row which calls a javascript code to
dynamically add a new row with language_name select box
the javascript code add_lang_row takes a parameter of array of
languages described above ie array of (lang_name, id ) pair which is
used to fill the select options...[ this is working fine given my
parameter is proper ]
But I cant call the script as
<a href=''javascript'' onclick=''add_lang_row(
<%= all_languages
%>)''>Add country</a>
so i tried ...
<script>
var list_of_langs;
<% for i in 1..@all_languages.length %>
list_of_langs[<%= i-1 %>][0] =
<%=@all_languages[i-1][0]%>
list_of_langs[<%=i-1%>][1] = <%=@all_languages[i-1][1]%>
</script>
I am getting syntax error .. :(
I am sure ruby will have some cool way of doing this .. as with habtm
etc etc...
can anyone help me here...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---