Code Monkey home page Code Monkey logo

custom_fields's Introduction

CustomFields

Manage custom fields to a mongoid document or a collection. This module is one of the core features we implemented in our custom cms named Locomotive.
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.

Requirements

ActiveSupport 3.2.9, MongoDB 2.0 and Mongoid 3.0.19

Examples

On a has_many relationship

class Company
  include CustomFields::Source

  has_many :employees

  custom_fields_for :employees
end

class Employee
  include CustomFields::Target

  field :name, String

  belongs_to :company, :inverse_of => :employees
end

company = Company.new
company.employees_custom_fields.build :label => 'His/her position', :name => 'position', :type => 'string', :required => true

company.save

company.employees.build :name => 'Michael Scott', :position => 'Regional manager'

another_company = Company.new
employee = company.employees.build
employee.position # returns a "not defined method" error

On the class itself

[IN PROGRESS]

class Company
  custom_fields_for_itself
end

company = Company.new
company.self_metadata_custom_fields.build :label => 'Shipping Address', :name => 'address', :type => 'text'

company.save

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

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

Contact

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

Copyright © 2012 NoCoffee, released under the MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.