2

I have a user created array which is displayed by a function in a table (this is all done with jquery on the client side). I want to save this to the database so it can be linked to and displayed again. I have my rails model and form setup to accept a string (presumably I must convert the array to a string) but I'm entirely unsure how to code this properly. I've followed this tutorial but I'm not sure where it's going wrong. I don't need an exact answer, just looking to be pointed in the right direction..

1 Answer 1

5

JavaScript

var arrayAsString = JSON.stringify(myArray);
sendToDatabaseUsingAJAX( arrayAsString );
// ... later ...
var arrayFromString = JSON.parse( arrayAsString );

Ruby

require 'json'
array_as_string = my_array.to_json
send_to_database( array_as_string )
# ... later ...
array_from_string = JSON.parse( array_as_string_gotten_from_db )
Sign up to request clarification or add additional context in comments.

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.