-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-43961: rails qs #52
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 4 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,75 @@ | ||||||||||
.. _mongoid-quick-start-rails: | ||||||||||
|
||||||||||
=========================== | ||||||||||
Quick Start (Ruby on Rails) | ||||||||||
=========================== | ||||||||||
|
||||||||||
.. facet:: | ||||||||||
:name: genre | ||||||||||
:values: tutorial | ||||||||||
|
||||||||||
.. meta:: | ||||||||||
:keywords: ruby framework, odm | ||||||||||
|
||||||||||
.. contents:: On this page | ||||||||||
:local: | ||||||||||
:backlinks: none | ||||||||||
:depth: 1 | ||||||||||
:class: singlecol | ||||||||||
|
||||||||||
Overview | ||||||||||
-------- | ||||||||||
|
||||||||||
This guide shows you how to use {+odm+} in a new **Ruby on Rails 7** web | ||||||||||
application, connect to a MongoDB cluster hosted on MongoDB Atlas, and | ||||||||||
perform read and write operations on the data in your cluster. | ||||||||||
|
||||||||||
.. tip:: | ||||||||||
|
||||||||||
If you prefer to connect to MongoDB by using the {+ruby-driver+} without | ||||||||||
{+odm+}, see the {+ruby-driver+} :ruby:`Quick Start guide | ||||||||||
</tutorials/quick-start/>`. | ||||||||||
|
||||||||||
{+odm+} is an Object-Document Mapper (ODM) framework for MongoDB in | ||||||||||
Ruby. By using {+odm+}, you can easily interact with your data and | ||||||||||
create flexible data models. | ||||||||||
|
||||||||||
Ruby on Rails, or Rails, is a web application framework for | ||||||||||
{+language+}. Rails applications use a model-view-controller (MVC) | ||||||||||
architecture that allows you to easily control how your data is | ||||||||||
modeled and displayed. {+odm+} replaces Rails' default | ||||||||||
``ActiveRecord`` adapter for data modeling. | ||||||||||
|
modeled and displayed. {+odm+} replaces Rails' default | |
``ActiveRecord`` adapter for data modeling. | |
modeled and displayed. {+odm+} replaces the default | |
``ActiveRecord`` adapter for data modeling in Rails. |
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: These last two paragraphs feel a little tacked on after the pointers to other docs. You could try:
- Moving these two paragraphs to just after the "Ruby on Rails..." paragraph, so the parallel structure with other explanatory paragraph is clear
- Moving the admonition and "To learn more..." paragraph to the end. Could also consider putting this in an admonition
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.
shuffled paragraphs
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||
.. _mongoid-quick-start-rails-connect-to-mongodb: | ||||||
|
||||||
================================= | ||||||
Configure Your MongoDB Connection | ||||||
================================= | ||||||
|
||||||
.. facet:: | ||||||
:name: genre | ||||||
:values: tutorial | ||||||
|
||||||
.. meta:: | ||||||
:keywords: test connection, runnable, code example | ||||||
|
||||||
.. procedure:: | ||||||
:style: connected | ||||||
|
||||||
.. step:: Configure application for MongoDB | ||||||
|
||||||
To configure your application to use MongoDB and {+odm+} as your | ||||||
ODM, run the following command from the root of your project: | ||||||
|
||||||
.. code-block:: bash | ||||||
|
||||||
bin/rails g mongoid:config | ||||||
|
||||||
After the command completes successfully, your application | ||||||
contains the ``config/mongoid.yml`` file to configure the | ||||||
connection to the MongoDB deployment. Your application also | ||||||
includes the ``config/initializers/mongoid.rb`` file for more | ||||||
advanced configuration. | ||||||
|
||||||
.. step:: Specify target database in connection string | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
When connecting to an Atlas cluster, you must specify the database that | ||||||
you want to interact with as the default database in your connection string. | ||||||
You must add the database name to your connection string **after the hostname**. | ||||||
|
||||||
|
||||||
The following example specifies the ``sample_restaurants`` target database | ||||||
in a sample connection string: | ||||||
|
||||||
.. code-block:: none | ||||||
|
||||||
mongodb+srv://user0:[email protected]/sample_restaurants | ||||||
|
||||||
.. step:: Specify connection | ||||||
|
.. step:: Specify connection | |
.. step:: Specify connection in mongoid.yml |
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:
Paste the following configuration into the ``mongoid.yml`` file, | |
Paste the following configuration into the ``config/mongoid.yml`` file, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. _mongoid-quick-start-rails-create-cxn-str: | ||
|
||
========================== | ||
Create a Connection String | ||
========================== | ||
|
||
.. include:: /includes/quick-start/create-cxn-str.rst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. _mongoid-quick-start-rails-create-deployment: | ||
|
||
=========================== | ||
Create a MongoDB Deployment | ||
=========================== | ||
|
||
.. include:: /includes/quick-start/create-deployment.rst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
.. _mongoid-quick-start-rails-download-and-install: | ||
|
||
==================== | ||
Download and Install | ||
==================== | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: tutorial | ||
|
||
.. meta:: | ||
:keywords: ruby framework, odm, code example | ||
|
||
Prerequisites | ||
------------- | ||
|
||
To create the Quick Start application by using Rails 7, you need the | ||
following software installed in your development environment: | ||
|
||
- `{+language+}. <https://www.ruby-lang.org/en/documentation/installation/>`__ | ||
Rails requires {+language+} v3.1.0 or later. Use the latest version | ||
to prevent version conflicts. | ||
- `RubyGems package manager. <https://rubygems.org/pages/download>`__ | ||
- A terminal app and shell. For MacOS users, use Terminal or a similar app. | ||
For Windows users, use PowerShell. | ||
|
||
.. tip:: Rails 6 Tutorial | ||
|
||
If you prefer to use Rails 6 to build your application, see the | ||
:ref:`mongoid-getting-started-rails-6` guide. | ||
|
||
Download and Install the {+odm+} and Framework Gems | ||
--------------------------------------------------- | ||
|
||
In {+language+}, packages are called **gems**. | ||
|
||
Complete the following steps to install and add the {+odm+} and Rails | ||
gems to your web application. | ||
|
||
.. procedure:: | ||
:style: connected | ||
|
||
.. step:: Install Rails | ||
|
||
Install the ``rails`` gem, which provides a command-line | ||
interface to create an application skeleton and application | ||
mongoKart marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
components. | ||
|
||
Run the following command to install ``rails``: | ||
|
||
.. code-block:: bash | ||
|
||
gem install rails | ||
|
||
.. step:: Create a Rails skeleton app | ||
|
||
Run the following commands to create a new Rails application | ||
directory and enter it: | ||
|
||
.. code-block:: bash | ||
|
||
rails new {+quickstart-rails-app-name+} --skip-active-record | ||
cd {+quickstart-rails-app-name+} | ||
|
||
The ``--skip-active-record`` flag instructs Rails to not add | ||
``ActiveRecord`` as a dependency, as you will use {+odm+} | ||
instead. | ||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. tip:: MacOS Installation Issue | ||
|
||
If you are using macOS, you might encounter issues when creating a | ||
new Rails app during the automatic bundle installation step. | ||
First, make sure that your macOS and `Xcode | ||
<https://developer.apple.com/xcode/>`__ versions are up to | ||
date. If you receive an error message similar to the following, | ||
you must update or configure your build tools: | ||
|
||
.. code-block:: none | ||
:copyable: false | ||
|
||
The compiler failed to generate an executable file. | ||
... | ||
(RuntimeError) You have to install development tools first. | ||
Check failure on line 83 in source/quick-start-rails/download-and-install.txt
|
||
|
||
Run the following commands to install Xcode command line tools: | ||
|
||
.. code-block:: bash | ||
|
||
xcode-select --install | ||
xcodebuild -license accept | ||
|
||
Then, try to run the ``bundle install`` command again. | ||
|
||
.. step:: Add the {+odm+} gem | ||
|
||
Open the ``Gemfile`` in your application and add the following | ||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
entry: | ||
|
||
.. code-block:: ruby | ||
|
||
gem 'mongoid' | ||
|
||
.. step:: Install gems | ||
|
||
Run the following command to install the gems into your | ||
application: | ||
|
||
.. code-block:: bash | ||
|
||
gem install bundler | ||
bundle install | ||
|
||
When the command runs successfully, the output in your | ||
shell contains a ``Bundle complete!`` message and describes the | ||
number of new gems installed. | ||
|
||
After completing these steps, you have a new Rails web application with | ||
{+odm+} installed. | ||
|
||
.. include:: /includes/quick-start/troubleshoot.rst |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.. _mongoid-quick-start-rails-next-steps: | ||
|
||
========== | ||
Next Steps | ||
========== | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: learn more | ||
|
||
Congratulations on completing the Quick Start tutorial for Ruby on Rails | ||
7! | ||
|
||
After you complete these steps, you have a Rails 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. | ||
|
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: for clarity
alternatively, add it in the first paragraph when you intro the term:
This guide shows you how to use {+odm+} in a new Ruby on Rails 7 (Rails) web
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: You could just say "Rails" or "Ruby on Rails" here, since you've already introduced both terms