Skip to content
This repository

Manage custom fields to a mongoid document or a collection

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 config
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 TODO
Octocat-spinner-32 custom_fields.gemspec


Manage custom fields to a mongoid document or a collection. This module is one of the core features we implemented in our custom cms, LocomotiveCMS.
Basically, its aim is to provide to editors a way to manage extra fields to a Mongoid document through, for instance, a web UI.

The main goals:

  • offering a very secure way to add / edit / delete extra fields to a Mongoid document
  • scoping the modifications added to a Mongoid document so that other documents of the same class won’t be updated.


ActiveSupport 3.2.13, MongoDB 2.0 and Mongoid 3.1.3


On a has_many relationship

class Company
  include CustomFields::Source

  has_many :employees

  custom_fields_for :employees

class Employee
  include CustomFields::Target

  field :name, String

  belongs_to :company, :inverse_of => :employees

company = :label => 'His/her position', :name => 'position', :type => 'string', :required => true :name => 'Michael Scott', :position => 'Regional manager'

another_company =
employee =
employee.position # returns a "not defined method" error

On the class itself


class Company

company = :label => 'Shipping Address', :name => 'address', :type => 'text'

company.self_metadata.address = '700 S Laflin, 60607 Chicago'

another_company =
other_company.self_metadata.address # returns a "not defined method" error


Feel free to contact me at didier at nocoffee dot fr.

Copyright © 2013 NoCoffee, released under the MIT license

Something went wrong with that request. Please try again.