Pass Ruby Array To JavaScript Array
While working on a functionality I came across a requirement to pass a ruby array to js array. I tried and googled for it and found a nice solution. Check it out :-
In console :-
$> u.subscribed_cug_list.map{|c|c.name}
=> ["abc", "Amazon", "cug10", "cug5", "cug7", "cug8", "cug9", "Dun", "Hello", "Nokia", "punjab", "Rodies", "SNcug", "SukhiGrp"]
this was my output from ruby, now I had to pass this ruby array to js array variable :-
var availableTags = ['<%= u.subscribed_cug_list.map{|c|c.name}.join('\',\'') %>'];
Done :-)

Leave a Comment