Nevermind, I figured it out: array.to_json works just fine. Way
simpler than I thought.
On Jan 19, 1:00 pm, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Im wondering how to go about passing a ruby array to a javascript
> function. I was able to do this the other way around and pass a
> javascript array to an action using JSON and convert it back to a ruby
> array:
>
> Object.toJSON(<%= array_or_string_for_javascript(@array) %>
>
> then in the action I was able to do:
>
> ruby_array = JSON.parse(params[:array])
>
> But this time I want to pass an array to a javascript function through
> a function call within :update
>
> render :update do |page|
> page << "setTime(#{time})"
> end
>
> where setTime is the javascript function and time is the ruby array.
> I can pass a number and it works fine, but with strings and arrays I
> get an error. How would I go about passing a ruby array to a
> javascript function in this context? Any help is greatly appreciated!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---