Using controller params in javascript

Hi :wave:t3:,

I’m trying to pass some values from the controller to a javascript graphing library. The values I need are arrays in the form of [“10/20/2019”, ”10/21/2019”] and [1.2, 2.3]. The problem is that when I try to access them in javascript they come out concatenated as 10/20/201910/21/2019 and 1.22.3.

I’ve tried accessing them directly via <%= @thing >, wrapping @thing in raw and Jason.decode!, writing it to data attributes on a hidden element, but they always come out the same.

I would assume this is a pretty common thing, and maybe I’m just not googling the right words?

Jason.encode!(@thing) is probably more what you are looking for, to ‘encode’ it into json, not decode. :slight_smile:

omg :man_facepalming:t3: classic


1 Like