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"}]
我該如何解決這個問題?