I have this code-snippet:
in my app/assets/javascripts/application.js
//= require jquery
//= require harddisk
//= require rails-ujs
//= require_tree .
in my app/assets/javascripts/harddisk.js.erb
var harddisk_locations = [<%= raw @harddisk_locations.to_json %>];
console.log(harddisk_locations);
in my app/models/harddisk.rb
@harddisk_locations = ["foo", "bar", "baz"];
But for some reason on the harddisk page in browser console
@harddisk_locations is null instead of an array with 3 elements.
Why is it so and how to fix?
It doesn't help if I move the
@harddisk_locations = ["foo", "bar", "baz"];
from harddisk-model into harddisks_controller.rb
harddisk.js.erbin views: stackoverflow.com/questions/18437282/… and also@harddisk_locationsin controller.