I have an array of strings declared in my controller that I need to use in a js file. Here is my code:
#controller
@cars = current_user.cars.completed.collect{|c| c.name.titleize }
puts "#{@cars.inspect}"
The puts
returns:
["Presentation 2", "Presentation 1"]
I now need to use the array in javascript, so I do:
//javascript
var lineChartData = {
labels : <%= @cars %>
}
The javascript is not working though because the browser is reading it as:
//javascruot
var lineChartData = {
labels : ["Presentation 2", "Presentation 1"],
}
I have tried using html_safe
like this:
#controller
@cars = current_user.cars.completed.collect{|c| c.name.titleize.html_safe }
puts "#{@cars.inspect}"
but it has no effect. How do I get the quotes to work properly?