home_controller.rb
class HomeController < ApplicationController
def index
@labels = ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'].to_json.html_safe
end
end
_main.js.erb
window.onload = function() {
var ctx = document.getElementById('fgm').getContext('2d');
console.log("<%= escape_javascript @labels %>");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: "<%= escape_javascript @labels %>",
журнал консоли браузера
["Red","Blue","Yellow","Green","Purple","Orange"]
отладка браузера
<script type="text/javascript">
window.onload = function() {
var ctx = document.getElementById('fgm').getContext('2d');
console.log("[\"Red\",\"Blue\",\"Yellow\",\"Green\",\"Purple\",\"Orange\"]");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: "[\"Red\",\"Blue\",\"Yellow\",\"Green\",\"Purple\",\"Orange\"]",
datasets: [{
label: '# of Votes',
Эта строка - моя проблема:
labels: "[\"Red\",\"Blue\",\"Yellow\",\"Green\",\"Purple\",\"Orange\"]",
, так как мне нужно, чтобы она не была заключена вцитаты например
labels: ["Red","Blue","Yellow","Green","Purple","Orange"],