Mongo Mapper


attr_protected allows you to specify a list of keys that cannot be set when using mass-assignment. It can be called multiple times, each call adds to the already declared attributes. It is recommended that you specify attr_accessible instead of attr_protected.

class User
  include MongoMapper::Document

  key :name, String
  key :email, String
  key :admin, Boolean

  attr_protected :admin

user ={
  :name => 'John',
  :email => '',
  :admin => true
})   # 'John'  # ''
user.admin  # nil
Fork me on GitHub