{"id":40773031,"url":"https://github.com/performant-software/user-defined-fields","last_synced_at":"2026-01-21T18:56:15.529Z","repository":{"id":60302962,"uuid":"536746183","full_name":"performant-software/user-defined-fields","owner":"performant-software","description":"Allow users to decide what data to capture","archived":false,"fork":false,"pushed_at":"2025-07-21T10:56:10.000Z","size":53,"stargazers_count":0,"open_issues_count":16,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-21T12:33:48.396Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/performant-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-14T20:18:54.000Z","updated_at":"2025-07-21T10:55:19.000Z","dependencies_parsed_at":"2024-07-16T21:13:47.128Z","dependency_job_id":"2a5a6a38-dc3a-4a63-9d99-33238034fe18","html_url":"https://github.com/performant-software/user-defined-fields","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/performant-software/user-defined-fields","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/performant-software%2Fuser-defined-fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/performant-software%2Fuser-defined-fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/performant-software%2Fuser-defined-fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/performant-software%2Fuser-defined-fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/performant-software","download_url":"https://codeload.github.com/performant-software/user-defined-fields/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/performant-software%2Fuser-defined-fields/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28639900,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T18:04:35.752Z","status":"ssl_error","status_checked_at":"2026-01-21T18:03:55.054Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-21T18:56:14.702Z","updated_at":"2026-01-21T18:56:15.522Z","avatar_url":"https://github.com/performant-software.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UserDefinedFields\nThis gem is designed to serve and storage and configuration for allowing CMS users to dynamically define fields for their models.\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'user_defined_fields'\n```\n\nAnd then execute:\n```bash\n$ bundle install\n```\n\nOr install it yourself as:\n```bash\n$ gem install user_defined_fields\n```\n\n## Usage\n\n### Migrations\nTo install the database table necessary to support user defined fields, use the following command:\n\n```bash\nbundle exec rails user_defined_fields:install:migrations\n```\n\nTo install the `user_defined` column on a model, use the following command:\n\n```bash\nbundle exec rails generate user_defined_fields:add my_model\n```\n\nThis will generate the following migration:\n\n```ruby\nclass AddUserDefinedFieldsToMyModel \u003c ActiveRecord::Migration[7.0]\n  def up\n    add_column :my_model, :user_defined, :jsonb, default: {}\n    add_index :my_model, :user_defined, using: :gin\n  end\n\n  def down\n    remove_index :my_model, :user_defined\n    remove_column :my_model, :user_defined\n  end\nend\n```\n\n### Routes\nThe user defined field routes can be added by mounting the engine in `routes.rb`:\n\n```ruby\nmount UserDefinedFields::Engine, at: '/user_defined_fields'\n```\n\n### Controllers\nEach individual field can be configured to be searchable or non-searchable. A searchable field will be included in the query when a user provides the \"search\" parameter on the API request.\n\nBehind the scenes, this uses the PostgreSQL `jsonb` query syntax to build the SQL used to find the record. For performance reasons, it's important that the GIN index be created on the `user_defined` field (explained above) and that the `user_defined` field doesn't contain nested objects.\n\n```ruby\nclass MyModelController \u003c ApplicationController\n  include UserDefinedFields::Queryable\nend\n```\n\n### Models\nModels that include the `UserDefinedFields::Fieldable` concern will be treated as the models that store the user defined data. The will be available in the dropdown list when configuring user defined fields.\n\nApplications that define user defined fields at the model level should call `resolve_defineable` class method with a lambda function that returns the `defineable` model.\n\n```ruby\nclass MyModel \u003c ApplicationRecord\n  include UserDefinedFields::Fieldable\n  \n  resolve_defineable -\u003e (my_model) { my_model.parent }\nend\n```\n\n### Serializers\nTo include the `user_defined_fields` array as a set of nested attributes, include the `UserDefinedFields::DefineableSerializer` in the serializer for whatever model the user defined fields belong to. This is only necessary for fields defined at the model level.\n\n```ruby\nclass ParentModelSerializer \u003c BaseSerializer\n  include UserDefinedFields::DefineableSerializer\nend\n```\n\nTo include the `user_defined` hash as an attribute, include the `UserDefinedFields::FieldableSerializer` in the model serializer.\n\n```ruby\nclass MyModelSerializer \u003c BaseSerializer\n  include UserDefinedFields::FieldableSerializer\nend\n```\n\n### Project Architecture\n\nUser defined fields can be configured one of two ways: At the application level, or at the model level.\n\n##### Application Level\nIf configured at the application level, each record in the specified table will contain the same user defined fields.\n\nFor example: You could define `first_name` and `last_name` fields for all of the `people` records. Anytime a user is editing a a person form, the `first_name` and `last_name` fields will be available as inputs.\n\n##### Model Level\nIf configured at the model level, records can contain different fields dependent on a parent record.\n\nFor example: You could define a `location` field for `resources` that belong to Project A, then define a `project_stage` field for `resources` that belong to Project B. On the edit for for Project A, only the `location` field will be available. On the edit form for Project B, only the `project_stage` field will be available.\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperformant-software%2Fuser-defined-fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperformant-software%2Fuser-defined-fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperformant-software%2Fuser-defined-fields/lists"}