{"id":19319759,"url":"https://github.com/hyperoslo/activeadmin_polymorphic","last_synced_at":"2025-04-22T17:32:15.501Z","repository":{"id":26889708,"uuid":"30350853","full_name":"hyperoslo/activeadmin_polymorphic","owner":"hyperoslo","description":null,"archived":false,"fork":false,"pushed_at":"2016-12-08T08:24:39.000Z","size":45,"stargazers_count":20,"open_issues_count":2,"forks_count":8,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-05-09T16:37:23.061Z","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/hyperoslo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-05T10:49:37.000Z","updated_at":"2024-02-16T15:16:19.000Z","dependencies_parsed_at":"2022-09-01T21:41:00.665Z","dependency_job_id":null,"html_url":"https://github.com/hyperoslo/activeadmin_polymorphic","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Factiveadmin_polymorphic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Factiveadmin_polymorphic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Factiveadmin_polymorphic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperoslo%2Factiveadmin_polymorphic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperoslo","download_url":"https://codeload.github.com/hyperoslo/activeadmin_polymorphic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223902223,"owners_count":17222333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-10T01:25:10.218Z","updated_at":"2024-11-10T01:25:10.671Z","avatar_url":"https://github.com/hyperoslo.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveadminPolymorphic\n\nActiveadmin Polymorphic gem is made to bring has_many polymorphic nested forms into your ActiveAdmin. ActiveAdmin users formtastic to build awesome forms, but formatstic itself doesn't support polymorphic relations. `activeadmin_polymorphic` gem is trying to solve that problem.\n\n![](https://s3.amazonaws.com/f.cl.ly/items/0b2F2t2R3D0o1O3F1R3e/Screen%20Shot%202015-02-05%20at%2012.57.04.png)\n\n# Features\n\n* polymorphic forms\n* validation\n* sortable behaviour\n* file uploads\n\n# Installation\n\nAdd this to your Gemfile:\n\n``` ruby\ngem \"activeadmin_polymorphic\"\n```\n\nand run `bundle install`.\n\nInclude assets in JS and CSS manifests\n\nJS:\n```\n#= require activeadmin_polymorphic\n```\n\nCSS:\n```\n@import \"activeadmin_polymorphic\";\n```\n\n# Usage\n\nTo use the gem, your model should have a related model, which works as a proxy to polymorphic relations.\n\n![](https://s3.amazonaws.com/f.cl.ly/items/2Z3M2V0b3Z342L2Z2R0N/Screen%20Shot%202015-02-05%20at%2013.37.36.png)\n\nThe gem extends activeadmin's form builder, so to enable the `has_many_polymorphic` method you need to override form builder using the `builder` option:\n\n```\n...\nSECTIONABLES = [Image, Text]\n\nform builder: ActiveadminPolymorphic::FormBuilder do |f|\n  f.polymorphic_has_many :sections, :sectionable, types: SECTIONABLES\nend\n...\n```\n\nThere are few options available:\n* first option, the name of polymorphic has_many association\n* second option, referes to polymorphied version of an association name (sectionable_id and sectaionable_type for example)\n* `types` - list of related models you want to use\n* `allow_destroy` - whether or not to allow destroying related objects\n* `sortable` - enables drag'n'drop for nested forms, accepts sortable column name, for example `sortable: :priority`\n\nSubforms for polymorphic relations are forms which you define in your ActiveAdmin. The gem fetches and submits them using some ajax magic.\n\n# Under the hood\n\nThis gem is a set of dirty hacks and tricks. Calling `polymorphic_has_many` makes it do the following things:\n\n* for new records it generates a dropdown with polymorphic types\n* for exising records it generates two hidden fields with `id` and `type`\n* then the real JavaScript starts, it extracts whole forms from polymorphic models new or edit pages, strips form actions, and inserts those forms right into the parent form\n* when you try to submit forms, JavaScript submits subforms first; if subforms are invalid, it reloads them with errors and interrupts the main form's submission process\n* after all subforms have been successfully saved, it strips them (because forms nested into other forms are semantically invalid, right?) and submits the parent form\n\n# File uploads in subforms\n\nThe gem relies on [rails ajax](https://github.com/rails/jquery-rails)'s form submissions, which doesn't allow to submit files directly. Workaround for this is asynchronous file submission using, for example [remotipart](https://github.com/JangoSteve/remotipart) for CarrierWave, or [refile](https://github.com/elabs/refile) with [refile-input](https://github.com/hyperoslo/refile-input). Note: before subforms submissions JavaScript strips all file inputs from the forms.\n\n# Testing\n\nTest's stucture is mostly copied from the original ActiveAdmin.\n\nInstall development dependencies with `bundle install`. To setup the test suit run `rake test`. Run tests with `bundle exec guard`. There aren't many of them, let's say there are quite a few.\n\n# In plan\n\n* allow to reuse existing polymorphic objects\n* check who it works with: models under a certain namespace\n* improve tests\n\n# License\n\n[MIT](LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperoslo%2Factiveadmin_polymorphic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperoslo%2Factiveadmin_polymorphic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperoslo%2Factiveadmin_polymorphic/lists"}