Rails - convert date string to javascript date object for tall charts

I am working on a dashboard application using Rails 3.1.1 / Highcharts with multiple charts, but I am stuck on converting a date string from a rails model to a javascript format that highcharts can accept.

My sample code is:

<%= @orders.map{ |f| [f.date, f.units.to_f] }.inspect %> 

Produces this conclusion:

 [[Fri, 04 Nov 2011, 182.0], [Sun, 06 Nov 2011, 189.0], [Tue, 08 Nov 2011, 178.0], [Thu, 10 Nov 2011, 115.0], [Sat, 12 Nov 2011, 135.0], [Mon, 14 Nov 2011, 120.0], [Thu, 17 Nov 2011, 181.0], [Sun, 20 Nov 2011, 145.0]] 

I need to have an array date format as follows:

 Date.UTC(2010, 10, 4). 

Any suggestions on the existing rail / ruby โ€‹โ€‹method or how to create an assistant?

+6
source share
1 answer

This is probably not the best way to do this, but I did:

 data: <%= @orders.map{ |f| [f.date.to_datetime.to_i, pdd.field_5x5 ] }.inspect %>, 

... which expresses the date in seconds.

+10
source

Source: https://habr.com/ru/post/902636/