Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !1020

Add support for editing polymorphic fields - Revisited

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Pablo Brasero requested to merge edit_polymorphic-pablobm into master Nov 01, 2017
  • Overview 21
  • Commits 14
  • Pipelines 0
  • Changes 49

This adds support for editing polymorphic fields. Props go to @pedantic-git, on whose work this is based. This PR supersedes https://github.com/thoughtbot/administrate/pull/984.

An important aspect of this PR is how it handles the polymorphic value. At heart, polymorphic values are split in two: an id and a type. Using the globalid gem we can obtain a string that represents both. However, we still need to tell that this string is indeed a globalid and not a literal value when we get to Administrate::ApplicationController#resource_params. I handle this by splitting the field in two:

  • my_field[value]: the global id, which includes both type and instance id.
  • my_field[type]: literally "Administrate::Field::Polymorphic"

Then #resource_params can look at the param values and treat them appropriately. If it's a simple value such a string, it does nothing special. However, if it comes in this value/type form, we treat it as polymorphic, reading the global id.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: edit_polymorphic-pablobm