Creating a Model
suggest changeCreate a model (call it User) by running:
$ rails g model User
which will generate the file app/models/user.rb:
class User
include Mongoid::Document
end
That is enough for a model whose only field is id. Unlike Active Record, Mongoid has no migration files. The model file holds the field definitions.
Timestamps are not automatically included in your model when you generate it. To add created_at and updated_at to your model, add
include Mongoid::Timestamps
to your model underneath include Mongoid::Document like so:
class User
include Mongoid::Document
include Mongoid::Timestamps
end
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents