How to pass a Ruby Array to a javascript function ?

I am passing a ruby array @myArray to a javascript function via rjs

page << "{ $ ('my_calendar').calendar_date_select.classForMatrix('#{@calendar_matrix}');}"

the js function is the following :

  classForMatrix: function(calendar_matrix) {   for (var i = 0; i<42; i++) {     cell = this.calendar_day_grid[i];     console.log(calendar_matrix(i));     if (calendar_matrix(i) == 1 ) {cell.addClassName("closed");}   }   },

and I get the following js error TypeError: calendar_matrix is not a function

where am I wrong ?

thanks for your lights

erwin

I am passing a ruby array @myArray to a javascript function via rjs

page << "{ $ ('my_calendar ').calendar_date_select.classForMatrix('#{@calendar_matrix}');}"

the js function is the following :

classForMatrix: function(calendar_matrix) {   for (var i = 0; i<42; i++) {     cell = this.calendar_day_grid[i];     console.log(calendar_matrix(i));     if (calendar_matrix(i) == 1 ) {cell.addClassName("closed");}   } },

and I get the following js error TypeError: calendar_matrix is not a function

where am I wrong ?

if calendar_matrix is an array you need calendar_matrix[i] not
calendar_matrix(i). On top of that you probably need to make it look like an array (ie
enclose it in , separate values with commas etc...). The
array_or_string_for_javascript looks like it will do that for you.

Fred

thanks a lot I realize it

using the @calendar_matrix.to_json send correctly the array and that's it....