0

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
}

2 Answers 2

1

If you're using jQuery, it's very easy to do this using $.post():

$.post('/some/page/here', {notes: jsonStr});
Sign up to request clarification or add additional context in comments.

1 Comment

how do you handle the JSON object in the controllers. I want to decode it and save the data in database? Thnx
0

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.