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

Substitue #to_s for Dashboard#title_attribute

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge to_s into master Apr 12, 2015
  • Overview 1
  • Commits 1
  • Pipelines 0
  • Changes 11

Created by: gracewashere

title_attribute was being used to display a link to each resource throughout the dashboards.

It was acting as a kind of unique identifier, but was restrictive in several ways:

  • The title_attribute had to correspond with a method on the model. It couldn't be computed from several methods.
  • Only the current dashboard could look up the correct method for displaying a resource. This causes problems for relationships like the BelongsToAdapter and HasManyAdapter, which need to know how to display other objects.

Moving to #to_s is good in several ways:

  • It makes representing an object super easy, with a single consistent method to call on each object.
  • It encourages developers to write good #to_s methods on each of their objects.

And bad in several ways:

  • If #to_s is not defined on a model, it defaults to the object's ID. This is not tied in any way to the database, so an object's identifier wouldn't be consistent throughout the dashboard.
  • If the user hasn't defined #to_s on a model, it doesn't noisily fail by default. If we wanted to noisily fail, we'd have to check against the default #to_s string and raise an error.

To fix the bad effects, there's room for a separate gem that generates better default #to_s methods for objects, by trying for attributes like name or title, and defaulting to id if those are not present.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: to_s