Reputation: 945
Hi I'm new to rails so please bear with me :) I want to send JSON object to rails and save it to database. basically I have a data entered by the user then I have a javascript function thats retrieves the data and convert it into JSON object. What i want is to sent the JSON object maybe through ajax to rails and save it to the database.Can anyone give me any idea how to do it. thnx
function save(){
----(some codes)
notesArray.push({ Index: i, Title: title.val(), Content: content.val()});
// json encode it
var jsonStr = JSON.stringify(notesArray);
//want to add code here to send to rails
}
Upvotes: 0
Views: 1227
Reputation: 842
As to "handle the JSON object in the controllers" you can use parsed_params = CGI.parse(params[:_json])
,then you can get what you what througt parsed_params[key1][key2]
Upvotes: 0