Substitue #to_s for Dashboard#title_attribute #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
title_attribute
was being used to display a link to each resourcethroughout the dashboards.
It was acting as a kind of unique identifier, but was restrictive in
several ways:
It couldn't be computed from several methods.
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:
method to call on each object.
#to_s
methods on each oftheir objects.
And bad in several ways:
#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.
#to_s
on a model, it doesn't noisily failby 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 attributeslike
name
ortitle
, and defaulting toid
if those are not present.