0
我有以下的哈希值的数组,我发送给我的控制器:遍历轨哈希阵列
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);
}
});
然后在控制器我想通过这些比较循环:
@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
我得到一个错误:> no implicit conversion of Symbol into Integer
和调试时,我发现,在我的循环中c
不规整一致,那么我送...
c: ["0", {"startdate"=>"01/01/2016", "enddate"=>"01/01/2016"}]
我该如何解决这个问题?