Modernized fork of locomotivecms/custom_fields, one of the LocomotiveCMS gems kept up to date under dahogenelst. Alpha (3.0.0.alpha1): in development, not used in production yet. Not published on rubygems.org: use it from GitHub.
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 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 and 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.
- Ruby 3.3+ (tested on 3.3 and 4.0)
- MongoDB 8 (tested; Mongoid 9 supports older servers)
- Mongoid 8 or 9
- ActiveSupport 7.1 or 8
gem 'custom_fields', github: 'dahogenelst/custom_fields', tag: 'v3.0.0.alpha1'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 = another_company.employees.build
employee.position # Returns a `not defined method` errorIN 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` errorRun bundle exec rspec (a MongoDB on localhost:27017).
Run COVERAGE=true bundle exec rspec.
Feel free to contact me at did at locomotivecms dot com.
Copyright (c) 2023 NoCoffee, released under the MIT License (MIT), see MIT-LICENSE.