-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't use #to_s
to display models in Administrate.
#129
Comments
@rikkipitt good call. We've gone back and forth on Where would you expect to see it? I'm thinking of adding a note to the |
@Graysonwright thanks for the quick reply. I missed those pull requests, cheers for referencing them. Albeit a short page, could it warrant its own section under something like "Customising Fields"? It might get lost in the Getting started page... I've used RailsAdmin extensively and I believe they try |
Yeah, it's hard to get a decent solution without getting too "magical". 😄 |
I think I'd like to see something like a method to override in the model - |
@jcutrell I like that idea - it might make it easier to fallback to a sensible default. It might work well in a helper method, like: def display_record(record)
record.try(:administrate_title) || "#{record.class} ##{record.id}"
end |
I agree with @jcutrell 's suggestion. Using I would consider even going a step further, and have users put their |
Agreed. We need to make sure things don't get too DSL'ly as that's the first guideline principle of the whole project... |
Perhaps it's best placed in the dashboard class somehow? Or maybe some kind of presentational class can be generated to accompany the dashboard? I agree - having an extra method on the model just for display doesn't seem right to me. I think something like a ViewModel (or whatever term you want to use) should wrap the model instance and decorate it with administrate-specific methods that delegate to underlying fallback methods when not defined by the end user.
|
#to_s
to display models in Administrate.
@jcutrell I think at the moment the Dashboard class is the best place for this. If we find ourselves adding a lot of view-specific methods in there, we can consider extracting a decorator layer. I'm working on a PR now. |
#191 introduces a fix for this issue - please give feedback there! |
Why are you guys not using the |
@lucianosousa I think the difference here is that we're looking to customize how the model identifier is displayed for the sake of an admin user (who may be non-technical), rather than display a serialized form of the model's primary key. Admins (or at least the ones I'm developing for) don't care about IDs-- they want to see something more descriptive, and what that means changes based on the domain. |
@maxkwallace I always - or most of the cases - assume the same URL in admin and regular pages.
I mean, there is none complex stuff in this issue. It's better use some default method to to this than generate a lot of complex code for different models/types |
@lucianosousa - I think we're talking about different things. This PR isn't related to URLs at all. We're changing how labels like these get generated in the app: I think you might be talking about the URLs, which are being generated by the |
hum, I see. my fault |
Just a minor note to request the documentation of the use of the
to_s
method for better representing objects across the various Administrate dashboards. E.g.has_many
select lists andbelongs_to
on index lists. This might catch out some newer Rails/Ruby users if not explicitly mentioned...Something along the lines of:
Example:
Thus instead of displaying
#<Tag:0x007fad07b7ad98>
, we can display the actual name of the tag.Thoughts?
The text was updated successfully, but these errors were encountered: