{"id":28646756,"url":"https://github.com/firedev/polymorph","last_synced_at":"2025-07-12T16:38:01.579Z","repository":{"id":4379558,"uuid":"44724331","full_name":"firedev/polymorph","owner":"firedev","description":"Frontend bits and pieces for Rails","archived":false,"fork":false,"pushed_at":"2025-05-28T18:29:05.000Z","size":51,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T02:06:50.484Z","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/firedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-22T05:35:17.000Z","updated_at":"2022-05-31T03:08:30.000Z","dependencies_parsed_at":"2022-08-28T23:12:28.052Z","dependency_job_id":null,"html_url":"https://github.com/firedev/polymorph","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/firedev/polymorph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firedev%2Fpolymorph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firedev%2Fpolymorph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firedev%2Fpolymorph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firedev%2Fpolymorph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firedev","download_url":"https://codeload.github.com/firedev/polymorph/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firedev%2Fpolymorph/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265024279,"owners_count":23699589,"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":"2025-06-13T02:06:49.608Z","updated_at":"2025-07-12T16:38:01.551Z","avatar_url":"https://github.com/firedev.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polymorph\n\n## 1. Installation\n\n### 1.1 Add Gemfile\n\n```ruby\n# Gemfile\n\ngem 'polymorph'\n```\n\n### 1.2 Mount Engine\n\n```ruby\n# config/routes.rb\n# Rails.application.routes.draw do\n\n  mount Polymorph::Engine, at: '/'\n\n# end\n```\n\n### 1.3 Initializer to help with authentication\n\nIf you skip it anybody could use new functions.\n\n```ruby\n# ininitalizers/polymorph.rb\n\nPolymorph.configure do |config|\n  config.authorize = lambda do |controller|\n    controller.authenticate_user!\n  end\nend\n```\n\n## 2. Orderable\n\nOrders models on their position column via `ordered` scope. If you are using it\nyou would have to add some additional dependencies:\n\n### Orderable Dependencies\n\n`Orderable` user drag-n-drop depends on jQuery UI.\n\n```ruby\n# Gemfile\n\ngem 'jquery-ui-rails'\n```\n\nIt also needs some js helpers:\n\n```javascript\n# application.js\n//= require jquery-ui/sortable\n//= require polymorph/polymorph\n```\n\nAnd an optional stylesheet for changing cursor shape:\n\n```css\n/*  application.css\n * = require polymorph\n */\n```\n\nDefault selector is `.admin [data-orderable]` so you have to add `.admin`\nclass somewhere for an authorized user.\n\n```slim\nbody class=(current_user.admin? \u0026\u0026 'admin')\n```\n\nOrderable items got to have its `#id` in HTML `id` element\n\n```\ndiv_for(model)\n```\nor\n```\ndiv id=dom_id(model)\n```\n\n### Orderable Installation.\n\nAdd `position:integer` to a model schema\n\n```sh\nrails g migration add_position_to_model position:integer\nrake db:migrate\n```\n\nInclude `Polymorph::Orderable` in the `Model` class\n\n```ruby\n# models/model.rb\n# class Model \u003c ActiveRecord::Base\n\n  include Polymorph::Orderable\n\n# end\n```\n\nDon't forget to use `ordered` scope\n\n```ruby\n# controllers/models_controller.rb\ndef index\n  @models = Model.ordered\nend\n```\n\nHTML selector\n\n```slim\n# index.html.slim\n\ndiv data-orderable=polymorph.orderable_path(Model)\n  = render @models\n```\n\n### Additional Orderable Parameters:\n\n**Axis** limits movement alone X or Y axes:\n\n```slim\ndata-orderable-axis=\"y\"\n```\n\n**Items** is an additional subselector for items that will be serialized and moved:\n\n```slim\ndata-orderable-items=\"\u003e .block\"\n```\n\n## 3. Paranoid\n\nThis module provides paranoid delete akin to\n[Paranoia](http://github.com/radar/paranoia) gem. But there is one important\ndifference. There are no callbacks.\n\nIt simply updates `deleted_at` so you can restore deleted entries with\nassociations associations intact.\n\nFirst create a migration:\n\n```ruby\nrails generate migration AddDeletedAtToModel deleted_at:datetime:index\nrake db:migrate\n```\n\nAdd concern to model:\n\n```ruby\n# models/model.rb\n# class Model \u003c ActiveRecord::Base\n\n  include Polymorph::Paranoid\n\n# end\n```\n\nYou need to add `Polymorph::Application` helper to Application Controller.\n\n```ruby\n# controllers/application_controller.rb\n# class ApplicationController \u003c ActionController::Base\n\n  helper Polymorph::ApplicationHelper\n\n# end\n```\n\nIncluded module sets up `default_scope` so soft-deleted entries are skipped.\nAdditional class method `paranoid_destroy` is added to the parent class in case\nyou want to wrap your own stuff.\n\n```\n# controllers/model_controller.rb\n# def destroy\n\n  @model.paranoid_destroy\n\n# end\n```\n\n## 4. Publishable\n\nThis one sets `published_at` in the same vein as with Paranoid.\n\nFirst a migration:\n\n```\nrails generation migration AddPublishedAtToModel published_at:datetime:index\nrake db:migrate\n```\n\nAdd concern:\n```\ninclude Polymorph::Publishable\n```\n\nThis module adds 'published' and 'unpublished' scope.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiredev%2Fpolymorph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiredev%2Fpolymorph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiredev%2Fpolymorph/lists"}