Why do my array indices in JavaScript get sent to Ruby as strings? Instead of having scores[0], I access the first element as scores["0"]. I also access my instance vars not as score.candidate_id, but as score["candidate_id"]. How do I make this work?
Code: My JQuery sends scores via AJAX through this function:
$.post("submit.com", {scores: results}, function(data) {console.log(data)}, "json")
where results is an array consisting of
{judge_id: x, category_id: y, candidate_id: z, score: s}
Ruby Back-end (Sinatra and not working)
post '/submit' do
woot = JSON.parse(params[:scores])
woot.each do |new_score|
Score.new({
score: new_score["score"],
pageant_id: Pageant.active.id,
candidate_id: new_score["candidate_id"],
judge_id: new_score["judge_id"],
category_id: new_score["category_id"]
}).save
end
params[:scores]["1"].inspect.to_json
end
resultsis an array?