I'm using Slim. When I describe a javascript:
block, I use this inside the JS code:
javascript:
var tteesstt = #{users.select(:id, :email).order(:email).to_json};
But I get this error:
SyntaxError: Unexpected token '&'. Expected a property name.
I tried to wrap in JSON.parse()
, but it did not help.
Tell me, please, how to solve the problem?
In Slim, we can do assign JSON data as JS object using {{}}
.
javascript:
var tteesstt = #{{users.select(:id, :email).order(:email).to_json}};
console.log(tteesstt); // ensures it gets the data as expected.