Skip to content

Commit 7ac3326

Browse files
authored
MONGOID-5645: Incorporate railsmdb README into Mongoid 9 docs (#5782)
* Add railsmdb to the Mongoid 9 release notes * Updated release notes * Updated installation instructions * Update release notes * Updated index
1 parent 43939c5 commit 7ac3326

File tree

3 files changed

+94
-11
lines changed

3 files changed

+94
-11
lines changed

source/index.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ Mongoid
66

77
.. default-domain:: mongodb
88

9-
Mongoid is the officially supported object-document mapper (ODM)
10-
for MongoDB in Ruby.
9+
Mongoid is the officially supported object-document mapper (ODM) for MongoDB in
10+
Ruby. To work with Mongoid from the command line using ``rails``-like tooling,
11+
the `railsmdb <https://github.com/mongodb/mongoid-railsmdb>`_ utility can be used.
1112

1213
.. toctree::
1314
:titlesonly:

source/installation.txt

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,33 @@ To install the gem with bundler, include the following in your ``Gemfile``:
3232
Using Mongoid with a New Rails Application
3333
==========================================
3434

35-
When creating a new Rails application and wish to use Mongoid for
36-
data access, give the ``--skip-active-record`` flag to the ``rails new``
37-
command to avoid depending on and configuring ActiveRecord..
35+
By using the `railsmdb CLI <https://github.com/mongodb/mongoid-railsmdb>`_ a new
36+
Ruby on Rails application can be quickly generated using the same options as
37+
``rails new``, but configured to work with MongoDB:
38+
39+
.. code-block:: sh
40+
41+
railsmdb new my_new_rails_app
42+
43+
The ``rails`` CLI can also be used, however when creating a new Rails application
44+
and where Mongoid will be used for data access, provide the ``--skip-active-record``
45+
flag to the ``rails new`` command to avoid depending on and configuring ActiveRecord.
46+
47+
Additional examples can be found in the `tutorials <tutorials.html>`_.
3848

3949
Using Mongoid with an Existing Rails Application
4050
================================================
4151

42-
When converting an existing Rails application to use Mongoid for data access,
43-
the ``config/application.rb`` file needs to be updated to remove the
44-
``require 'rails/all'`` line and explicitly include the required frameworks
45-
(which could be all of the frameworks provided by Rails with the exception of
46-
ActiveRecord). Any references to ActiveRecord in files in the ``config``
47-
directory and in the models also need to be removed.
52+
Using the `railsmdb CLI <https://github.com/mongodb/mongoid-railsmdb>`_ an existing
53+
Rails application can easily be configured for use with Mongoid:
54+
55+
.. code-block:: sh
56+
57+
railsmdb setup
58+
59+
Converting an existing Rails application without using ``railsmdb`` can be done
60+
by updating the ``config/application.rb`` file to remove the ``require 'rails/all'``
61+
line and explicitly include the required frameworks (which could be all of the
62+
frameworks provided by Rails with the exception ofActiveRecord).
63+
Any references to ActiveRecord in files in the ``config`` directory and in the
64+
models also need to be removed.

source/release-notes/mongoid-9.0.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,71 @@ The complete list of releases is available `on GitHub
1717
please consult GitHub releases for detailed release notes and JIRA for
1818
the complete list of issues fixed in each release, including bug fixes.
1919

20+
Railsmdb for Mongoid
21+
--------------------
22+
23+
To coincide with the release of Mongoid 9.0 a new command-line utility for creating,
24+
updating, managing, and maintaining Rails applications has also
25+
been made generally available!
26+
27+
``railsmdb`` makes it easier to work with MongoDB from the command line through
28+
common generators that Ruby on Rails developers are already familiar with.
29+
30+
For example, you can use ``railsmdb`` to generate stubs for new Mongoid models:
31+
32+
.. code-block:: sh
33+
34+
$ bin/railsmdb generate model person
35+
36+
This will create a new model at ``app/models/person.rb``:
37+
38+
.. code-block:: ruby
39+
40+
class Person
41+
include Mongoid::Document
42+
include Mongoid::Timestamp
43+
end
44+
45+
You can specify the fields of the model as well:
46+
47+
.. code-block:: ruby
48+
49+
# bin/railsmdb generate model person name:string birth:date
50+
51+
class Person
52+
include Mongoid::Document
53+
include Mongoid::Timestamp
54+
field :name, type: String
55+
field :birth, type: Date
56+
end
57+
58+
You can instruct the generator to make the new model a subclass of another,
59+
by passing the ``--parent`` option:
60+
61+
.. code-block:: ruby
62+
63+
# bin/railsmdb generate model student --parent=person
64+
65+
class Student < Person
66+
include Mongoid::Timestamp
67+
end
68+
69+
And if you need to store your models in a different collection than can be
70+
inferred from the model name, you can specify ``--collection``:
71+
72+
.. code-block:: ruby
73+
74+
# bin/railsmdb generate model course --collection=classes
75+
76+
class Course
77+
include Mongoid::Document
78+
include Mongoid::Timestamp
79+
store_in collection: 'classes'
80+
end
81+
82+
For more information see the `GitHub Repository <https://github.com/mongodb/mongoid-railsmdb>`_.
83+
84+
2085
Aggregable API is deprecated
2186
----------------------------
2287

0 commit comments

Comments
 (0)