I have the following array of hashes that I send to my controller:
comparisons = [{
"startdate": "01/01/2016",
"enddate": "01/02/2016"
}, {
"startdate": "01/03/2016",
"enddate": "01/04/2016"
}, {
"startdate": "01/05/2016",
"enddate": "01/06/2016"
}, {
"startdate": "01/05/2016",
"enddate": "01/06/2016"
}];
$.ajax({
url: '/get_data',
method: 'GET',
dataType: 'JSON',
data: {
startdate: '01/01/2016',
enddate: '01/01/2016',
comparisons: comparisons
},
success: function (data) {
console.log(data);
}
});
And then in the controller I want to loop through these comparisons:
@comparisons = []
if !params[:comparisons].blank?
params[:comparisons].each do |c|
@comparisons.push({:startdate => c[:startdate], :enddate => c[:enddate], :data => get_data(c[:startdate], c[:enddate], 'week')})
end
end
I get an error: > no implicit conversion of Symbol into Integer
And when debugging I'm finding that the c in my loop isn't structured the same as what I'm sending...
c: ["0", {"startdate"=>"01/01/2016", "enddate"=>"01/01/2016"}]
How can I fix this?