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
  • !1737

Change the way polymorphic fields display links

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/rwehresmann/correctly_display_polymorphic_field into master Aug 08, 2020
  • Overview 2
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: rwehresmann

In one of my recent projects using administrate I made a change in the _show of the polymorphic field. It attended my needs, and I think it's the way to go.

Contextualizing: The valid_action? implementation receives as second argument the resource class name (constantize), and so will look for the correspondent controller and check if the action exists. In the polymorphic field, we're using this to display the attribute as a link or just plain text.

The problem: In the _show partial we check for the field attribute, that will return just the attribute name, and polymorphic fields constantly have attribute names that don't correspond whit any controller name. Here is an example: I can have an Address model that have a polymorphic association that receives the name of owner, and the owner can be a Shop and User model. We have the ShopsController and UsersController, but not an OwnersController. As result, we'll be showing the owner as plain text only.

The solution: Just inform the field data class instead of the attribute name. Doing so, using the example described above, we'll be checking for the ShopsController and UsersController instead of the OwnersController, properly showing the owner as a link.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/rwehresmann/correctly_display_polymorphic_field