@@ -105,7 +105,6 @@ Add Mongoid
105
105
`mongoid <https://rubygems.org/gems/mongoid/>`_ gem:
106
106
107
107
.. code-block:: ruby
108
- :name: Gemfile
109
108
:caption: Gemfile
110
109
111
110
gem 'mongoid', '~> 7.0.5'
@@ -132,6 +131,8 @@ Note that as we are not using ActiveRecord we will not have a ``database.yml``
132
131
file.
133
132
134
133
134
+ .. _run-locally:
135
+
135
136
Run MongoDB Locally
136
137
-------------------
137
138
@@ -157,6 +158,8 @@ like this:
157
158
server_selection_timeout: 1
158
159
159
160
161
+ .. _use-atlas:
162
+
160
163
Use MongoDB Atlas
161
164
-----------------
162
165
@@ -247,7 +250,6 @@ Open the ``Post`` model file, ``app/models/post.rb``, and add a ``has_many``
247
250
association for the comments:
248
251
249
252
.. code-block:: ruby
250
- :name: app/models/post.rb
251
253
:caption: app/models/post.rb
252
254
253
255
class Post
@@ -267,7 +269,6 @@ association for the comments:
267
269
generated ``embedded_in`` association to ``belongs_to``:
268
270
269
271
.. code-block:: ruby
270
- :name: app/models/comment.rb
271
272
:caption: app/models/comment.rb
272
273
273
274
class Comment
@@ -283,7 +284,6 @@ Open the post show view file, ``app/views/posts/show.html.erb``, and add
283
284
a section rendering existing comments and prompting to leave a new comment:
284
285
285
286
.. code-block:: html
286
- :name: app/views/posts/show.html.erb
287
287
:caption: app/views/posts/show.html.erb
288
288
289
289
<section class="section comments">
@@ -306,7 +306,6 @@ from ``text_field`` to ``text_area``, as well as the type of field for
306
306
should look like this:
307
307
308
308
.. code-block:: html
309
- :name: app/views/comments/_form.html.erb
310
309
:caption: app/views/comments/_form.html.erb
311
310
312
311
<%= form_with(model: comment, local: true) do |form| %>
@@ -345,7 +344,6 @@ Create a partial for the comment view, ``app/views/comments/_comment.html.erb``
345
344
with the following contents:
346
345
347
346
.. code-block:: html
348
- :name: app/views/comments/_comment.html.erb
349
347
:caption: app/views/comments/_comment.html.erb
350
348
351
349
<p>
@@ -377,7 +375,6 @@ Remove or comment out any RDBMS libraries like ``sqlite``, ``pg`` etc.
377
375
mentioned in ``Gemfile``, and add ``mongoid``:
378
376
379
377
.. code-block:: ruby
380
- :name: Gemfile
381
378
:caption: Gemfile
382
379
383
380
gem 'mongoid', '~> 7.0.5'
@@ -399,7 +396,6 @@ Examine ``config/application.rb``. If it is requiring all components of Rails
399
396
via ``require 'rails/all'``, change it to require individual frameworks:
400
397
401
398
.. code-block:: ruby
402
- :name: config/application.rb
403
399
:caption: config/application.rb
404
400
405
401
# Remove or comment out
@@ -472,9 +468,9 @@ Generate the default Mongoid configuration:
472
468
This generator will create the ``config/mongoid.yml`` configuration file,
473
469
which is used to configure the connection to the MongoDB deployment.
474
470
475
- Review the sections `Run MongoDB Locally`_ and `Use MongoDB Atlas`_
476
- to decide how you would like to deploy MongoDB, and adjust Mongoid
477
- configuration (``config/mongoid.yml``) to match.
471
+ Review the sections :ref: `Run MongoDB Locally <run-locally>` and
472
+ :ref:`Use MongoDB Atlas <use-atlas>` to decide how you would like to deploy
473
+ MongoDB, and adjust Mongoid configuration (``config/mongoid.yml``) to match.
478
474
479
475
Adjust Models
480
476
-------------
@@ -491,7 +487,6 @@ explicit field definitions).
491
487
For example, a bare-bones Post model may look like this in ActiveRecord:
492
488
493
489
.. code-block:: ruby
494
- :name: app/models/post.rb
495
490
:caption: app/models/post.rb
496
491
497
492
class Post < ApplicationRecord
@@ -501,7 +496,6 @@ For example, a bare-bones Post model may look like this in ActiveRecord:
501
496
The same model may look like this in Mongoid:
502
497
503
498
.. code-block:: ruby
504
- :name: app/models/post.rb
505
499
:caption: app/models/post.rb
506
500
507
501
class Post
@@ -516,7 +510,6 @@ The same model may look like this in Mongoid:
516
510
Or like this with dynamic fields:
517
511
518
512
.. code-block:: ruby
519
- :name: app/models/post.rb
520
513
:caption: app/models/post.rb
521
514
522
515
class Post
@@ -555,5 +548,5 @@ as when creating a regular application, with the only change being the
555
548
Mongoid follows the same process described above for regular Rails applications.
556
549
557
550
A complete Rails API application similar to the one described in this tutorial
558
- can be found in the ` mongoid-demo GitHub repository
551
+ can be found in ` the mongoid-demo GitHub repository
559
552
<https://github.com/mongoid/mongoid-demo/tree/master/rails-api>`_.
0 commit comments