{"id":19474614,"url":"https://github.com/tomasc/simple_form_nested_fields","last_synced_at":"2026-06-11T02:31:38.654Z","repository":{"id":33143255,"uuid":"149270706","full_name":"tomasc/simple_form_nested_fields","owner":"tomasc","description":"Nested fields helper for simple_form.","archived":false,"fork":false,"pushed_at":"2023-01-19T09:22:26.000Z","size":962,"stargazers_count":0,"open_issues_count":41,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-04-05T13:05:44.733Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/tomasc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-18T10:32:42.000Z","updated_at":"2019-02-18T10:08:41.000Z","dependencies_parsed_at":"2023-02-10T21:50:29.528Z","dependency_job_id":null,"html_url":"https://github.com/tomasc/simple_form_nested_fields","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/tomasc/simple_form_nested_fields","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fsimple_form_nested_fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fsimple_form_nested_fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fsimple_form_nested_fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fsimple_form_nested_fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasc","download_url":"https://codeload.github.com/tomasc/simple_form_nested_fields/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasc%2Fsimple_form_nested_fields/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34180147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-11-10T19:25:52.490Z","updated_at":"2026-06-11T02:31:38.606Z","avatar_url":"https://github.com/tomasc.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Form Nested Fields\n\n[![Build Status](https://travis-ci.org/tomasc/simple_form_nested_fields.svg)](https://travis-ci.org/tomasc/simple_form_nested_fields) [![Gem Version](https://badge.fury.io/rb/simple_form_nested_fields.svg)](http://badge.fury.io/rb/simple_form_nested_fields) [![Coverage Status](https://img.shields.io/coveralls/tomasc/simple_form_nested_fields.svg)](https://coveralls.io/r/tomasc/simple_form_nested_fields)\n\nNested fields helper for [`simple_form`](https://github.com/plataformatec/simple_form).\n\nMakes it easier to handle forms with referenced/embedded models and attributes;\ne.g. a document with embedded texts, a project with referenced tasks, or an\ninvoice with line items.\n\nWorks with standard Rails forms and SimpleForm.\n\n## Dependencies\n\nThis gem depends on jQuery.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'simple_form_nested_fields'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install simple_form_nested_fields\n\nIf using sprockets, require the javascript in your `application.js`:\n\n```js\n//= require simple_form_nested_fields\n```\n\nand initialise the plugin like this:\n\n```js\n$(document).ready(\n  function() {\n    $(\".simple_form_nested_fields\").SimpleFormNestedFields()\n  }\n)\n```\n\n## Usage\n\nSuppose you have a model `MyDoc`, which embeds `texts`:\n\n```ruby\n# app/models/my_doc.rb\nclass MyDoc\n  include Mongoid::Document\n  embeds_many :texts, class_name: 'Text'\n  accepts_nested_attributes_for :texts, allow_destroy: true\nend\n\n# app/models/text.rb\nclass Text\n  include Mongoid::Document\n  field :body, type: String\n  embedded_in :my_doc, class_name: 'MyDoc'\nend\n```\n\nYou can then use the `nested_fields_for` helper to work with the texts in your\nform:\n\n```slim\n= simple_form_for @my_doc do |f|\n  = f.nested_fields_for :texts\n  = f.submit\n```\n\nThis will render the `texts/_fields` partial, in which you can use the `fields`\nhelper:\n\n```slim\n// app/views/my_docs/texts/_fields.html.slim\n= fields.input :body\n```\n\n### Inheritance\n\nSubclassing of the relation class is handled automatically by default with:\n\n* partials corresponding to each subclass\n* select input next to the add link that allows the user choose the subclass to be added\n\nThe choice of classes can be configured as follows:\n\n```slim\n= f.nested_fields_for :variants, nil, item_classes: [MyDoc::Variant::One, MyDoc::Variant::Two]\n```\n\n### Sortable\n\nMaking the nested fields sortable is straight forward.\n\nUsing our `MyDoc` and `texts` example, the models would look like this (note the\n`order` on the `embeds_many` and the `position` field on the `Text`):\n\n```ruby\n# app/models/my_doc.rb\nclass MyDoc\n  include Mongoid::Document\n  embeds_many :texts, class_name: 'Text', order: :position.asc\n  accepts_nested_attributes_for :texts, allow_destroy: true\nend\n\n# app/models/text.rb\nclass Text\n  include Mongoid::Document\n  field :body, type: String\n  field :position, type: Integer\n  embedded_in :my_doc, class_name: 'MyDoc'\nend\n```\n\nThen in your `MyDoc` form simply pass the `sortable` option to the\n`nested_fields_for` helper (note that in order to pass the option parameter, you\nhave to pass the second parameter: the collection/record object):\n\n```slim\n= simple_form_for @my_doc do |f|\n  = f.nested_fields_for :texts, @my_doc.texts, sortable: true\n  = f.submit\n```\n\nPlease note the `position` input is automatically added to the partial.\n\n### Configuration\n\n#### Custom partial path\n\nYou can override the default `_fields` partial lookup path as follows:\n\n```slim\n= simple_form_for @my_doc do |f|\n  = f.nested_fields_for :texts, nil, partial: 'my/own/path/to/fields'\n  = f.submit\n```\n\n#### I18n\n\nYou can change the text on the add and remove links by overriding the locale\nfile:\n\n```YAML\n# config/locales/simple_form_nested_fields.en.yml\nen:\n  simple_form_nested_fields:\n    links:\n      add: 'Add %{model_name}'\n      remove: 'Remove'\n```\n\n### Styling\n\nThe gem has no default styling, but leaves that up to you.\nFor reference, here's an example markup:\n\n```html\n\u003cdiv class=\"simple_form_nested_fields simple_form_nested_fields--texts\"\u003e\n  \u003cdiv class=\"simple_form_nested_fields__title\"\u003eTexts\u003c/div\u003e\n  \u003cdiv class=\"simple_form_nested_fields__items\"\u003e\n    \u003cdiv class=\"simple_form_nested_fields__item simple_form_nested_fields__item--new\"\u003e\n      \u003c!-- fields --\u003e\n      \u003ca class=\"simple_form_nested_fields__link simple_form_nested_fields__link--remove\"\u003eRemove\u003c/a\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n  \u003cdiv class=\"simple_form_nested_fields__links\"\u003e\n    \u003ca class=\"simple_form_nested_fields__link simple_form_nested_fields__link--add\"\u003eAdd Title\u003c/a\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n\n## Todo\n\n* Sortable field name should be configurable (`position` by default)\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/tomasc/simple_form_nested_fields. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\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%2Ftomasc%2Fsimple_form_nested_fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasc%2Fsimple_form_nested_fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasc%2Fsimple_form_nested_fields/lists"}