Ruby on Rails Fields


Example

As per the Mongoid Documentation, there are 16 valid field types:

  • Array
  • BigDecimal
  • Boolean
  • Date
  • DateTime
  • Float
  • Hash
  • Integer
  • BSON::ObjectId
  • BSON::Binary
  • Range
  • Regexp
  • String
  • Symbol
  • Time
  • TimeWithZone

To add a field (let's call it name and have it be a String), add this to your model file:

field :name, type: String

To set a default value, just pass in the default option:

field :name, type: String, default: ""