Based on the guide, it looks like Administrate only can customize an existing field because the Field assumes the original value will be passed through the data variable. How do I render on show page if the "new field" needs to be computed using more than its own original value?
For example, I have a place model that stores geocoded coordinates from Google. Instead of just displaying the lat & lng, I'd like to also show a static google map image on the show page. Google provides a very easy URL to generate the static image, however, this url needs both the lat & lng in order to work. I couldn't figure out how to add this image to the show page because this new field, if we gonna create a new field, needs data from two other attributes, lat & lng.
I am probably missing something very simple, hopefully. Appreciate any help in advance!
For values not in a column, I usually just define a method in the model and reference it in the dashboard. For example:
class Place < AplicationRecord
def google_maps_url
"www.google.com/maps?lat=#{lat}&long=#{long}"
end
end
class PlaceDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
google_maps_url: Field::String
}
end
Something like this should work with the example you posted form the guide.
Another way of solving this would be to use a presenter, which were looking at in #1773 and it's related issues. I'm going to close this as there's an immediate solution too. Thanks!
Most helpful comment
For values not in a column, I usually just define a method in the model and reference it in the dashboard. For example:
Something like this should work with the example you posted form the guide.