I'm building a RESTful web application with ruby + sinatra. The data is stored in a MongoDB database and I use MongoMapper to do this.
One of my models has a nested hash key:
{'Key' => {'ObjectA_id' => ['ObjectB1_id', 'ObjectB2_id', ... , 'ObjectBn_id']}}
As you can see it's a hash whose key is a string and the value is another hash that maps an array of object IDs* (let's call the model Model B
) to an id of Model A
.
*(these are technically also Strings in fact, cause you cannot store a real BSON ObjectID in a hash)
The problem is that I wouldn't know how to begin to send this data to the server. Normally I use a form like this:
<form action="/create" method="post">
<input type="text" name="myField"/>
<input type="submit"/>
</form>
And on the server side I can access whatever the user filled in in myField
with this code:
post '/create' do
myField = params[:myField]
end
The problem is obviously that I can never do this purely with a HTML form, so I wonder: how do I tackle this? I was thinking javascript/jquery, but then I wonder:
- How do I simulate a hash in javascript/jquery?
- How do I send it with the other form data?
- How do I access it on the server and what will it look like?