An array of rails displays a strange format in production

Has anyone seen this array error before? I have a helper method that returns an array. In development mode on my laptop, it returns an array in the expected format:

var fire = [[1349083353000, 8.860000000000582], [1349085153000, 19.779999999999745], [1349086953000, 20.289999999999964], [1349088753000, 29.850000000000364], [1349090553000, 3.7999999999992724]]; 

BUT the same code in production returns a strange array format:

 var fire = 135175422800015.5135175602800020.0135175782800018.99135175962800012.33135176142800019.13135176322800029.55135176502800020.13135176682800077.34 

I tried to check the output in the rails console on any machine, and the production output is the same array format. I created a new array from the rails console in production and works as expected to output the correct array format.

Has anyone seen this weirdness?

 Rails version:3.2.8 Ruby Version:1.9.3p-125 
+4
source share
1 answer

You are probably working on Ruby 1.9 and deploying on Ruby 1.8. The default behavior for handling arrays is different.

In Ruby 1.8, array.to_s equivalent to array.join('') .

In Ruby 1.9, array.to_s equivalent to array.inspect .

If you need the correct behavior for both, and you use JavaScript, you can make it as JSON using array.to_json instead.

+7
source

All Articles