forked from mongodb/docs-mongoid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite-data.txt
46 lines (31 loc) · 1.24 KB
/
write-data.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.. _mongoid-quick-start-sinatra-write-data:
===============================
Write Data to MongoDB - Sinatra
===============================
.. facet::
:name: genre
:values: tutorial
.. meta::
:keywords: test connection, runnable, code example
.. procedure::
:style: connected
.. step:: Add a web route to insert data
In the ``app.rb`` file, add a ``post`` route called
``add_restaurant``, as shown in the following code:
.. code-block:: ruby
post '/add_restaurant' do
Restaurant.create!(params[:restaurant])
end
.. step:: Post a request to create a restaurant entry
Send a ``Restaurant`` instance to the ``add_restaurant`` endpoint
by running the following command from the application root
directory:
.. code-block:: bash
curl -d \
'restaurant[name]=Good+Earth+Cafe&restaurant[cuisine]=Cafe&restaurant[borough]=Queens' \
http://localhost:4567/add_restaurant
.. step:: View the data
Refresh http://localhost:4567/list_restaurants in your web browser
to view the new restaurant entry that you submitted. The inserted
restaurant appears at the bottom of the list.
.. include:: /includes/quick-start/troubleshoot.rst