-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-44008: read/write sinatra quickstart #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.. _mongoid-quick-start-sinatra-next-steps: | ||
|
||
========== | ||
Next Steps | ||
========== | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: learn more | ||
|
||
Congratulations on completing the Quick Start tutorial for Sinatra! | ||
|
||
After you complete these steps, you have a Sinatra web application that | ||
uses {+odm+} to connect to your MongoDB deployment, run a query on | ||
the sample data, and render retrieved results. | ||
|
||
.. TODO You can download the completed web application project by cloning the | ||
.. `mongoid-quickstart <>`__ | ||
.. GitHub repository. | ||
|
||
.. TODO Learn more about {+odm+} features from the following resources: | ||
|
||
.. - :ref:`mongoid-fundamentals-connection`: learn how to configure your MongoDB | ||
.. connection. | ||
.. | ||
.. - :ref:`mongoid-usage-examples`: see code examples of frequently used MongoDB | ||
.. operations. | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,150 @@ | ||||||||
.. _mongoid-quick-start-sinatra-view-data: | ||||||||
|
||||||||
================= | ||||||||
View MongoDB Data | ||||||||
================= | ||||||||
|
||||||||
.. facet:: | ||||||||
:name: genre | ||||||||
:values: tutorial | ||||||||
|
||||||||
.. meta:: | ||||||||
:keywords: test connection, runnable, code example | ||||||||
|
||||||||
.. procedure:: | ||||||||
:style: connected | ||||||||
|
||||||||
.. step:: Create an application file | ||||||||
|
||||||||
At the root level of your project, create a file called ``app.rb``. | ||||||||
Paste the following contents into the ``app.rb`` file to | ||||||||
load the necessary gems and your configuration file: | ||||||||
|
||||||||
.. code-block:: ruby | ||||||||
|
||||||||
require 'sinatra' | ||||||||
require 'mongoid' | ||||||||
|
||||||||
Mongoid.load!(File.join(File.dirname(__FILE__), 'config', 'mongoid.yml')) | ||||||||
|
||||||||
.. step:: Create a data model | ||||||||
|
||||||||
In the ``app.rb`` file, create a model called ``Restaurant`` | ||||||||
to represent data from the sample ``restaurants`` collection in | ||||||||
your MongoDB database: | ||||||||
|
your MongoDB database: | |
the ``sample_restaurants`` database: |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: since this is a procedure step, I'd change the verb tense:
To display your data in a specified way by using HTML, you can | |
create a **view**. | |
Create a **view** to display your data in a specified way by using HTML. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: clarify which file you're editing
Replace the ``list_restaurants`` route with the following code to | |
Replace the ``list_restaurants`` route in the ``app.rb`` file with the following code to |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,43 @@ | ||||||
.. _mongoid-quick-start-sinatra-write-data: | ||||||
|
||||||
===================== | ||||||
Write Data to MongoDB | ||||||
===================== | ||||||
|
||||||
.. 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 in your shell: | ||||||
|
by running the following command in your shell: | |
from the application root directory: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: capitalize the first word after these colons