Reputation: 3351
I want to create a JSON object out of ruby object on view file like
:coffeescript
files = {}
- @filelist.each do |f|
= files[f[0]] = f[1]
console.log(files)
it gives me an "Unexpected logic" error
following is array declared in controller
@filelist = Array.new
@filelist.push(['ref','count'])
@filelist.push(['input1','count'])
@filelist.push(['input2','count'])
Upvotes: 1
Views: 784
Reputation: 3358
In your view you first have to convert ruby array to json (inside view):
var filelists = $.parseJSON(<%= @filelist.to_json %>);
Then create a json object in view:
var jsonObj = {};
$.each(filelists, function(obj,index){
jsonObj[obj[0]] = obj[1];
});
Upvotes: 1