Q:

Pass ruby array in js file

I have an array obtained from a query in my controller
@users

I'm able to show the result on my view, but I need to pass it into a ".js" file.
I have found that I need to use json so I have written this on my ".js"
var dataset = {
  ex1: [<%= raw @users.to_json %>],
  ex2: [100, 200, 200, 200, 200, 200, 200, 200, 200, 200]
};

but it doesn't work. Normally my view process static data on load, now I need to dinamically change these.
I have also added 
//= require json

but no luck.
Any idea?

A:

Your file has to be named: myfile.js.erb
This means your file content will be first evaluated for ruby code THEN for javascript code.
This is why your views are named myview.html.erb or myview.html.haml etc...
The same way goes for javascript and css assets: their names end with .js.coffee or .css.scss in order for them to be evaluated for CoffeScript or SCSS then Javascript or CSS.

