My back end is my Rails server which sends JSON data to my front end. In the front end, I am using javascript and jQuery which processes my JSON data and displays some of it.
Now, the user can inputs a number depending on the data displayed to it.
So, on the basis of input from user, certain changes are made to JSON data received earlier and send it back to my back-end as properly encoded JSON.
My question is how can I process this JSON data at the server and store the inputs filled by the user?
Not sure why you’d need to send the data back as JSON since Rails can just handle the form data normally, as thomasfedb says. But if you definitely do need to, you can use the jQuery
serializeArraymethod and then do a quick conversion from array to JSON. See the following:http://api.jquery.com/serializeArray/#comment-47479466
If you go down this route, you could use the
stringifymethod in JSON2.js to create valid JSON data from your object.http://www.json.org/js.html
edited:
Sorry, just realised that you’ve already got that far! Should have read the question properly.
You can use this JSON ruby implementation to
parsethe JSON data:and then just use the
savemethod fromActiveRecord::Baseto save your record.