Creating a Model

suggest change

Create 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents