Administrate: Customize association name

Created on 8 Nov 2016  路  2Comments  路  Source: thoughtbot/administrate

Is there a way to customize association name that is displayed on dashboard? Currently I see #. Can I somehow speficy that name field has to be used instead?

Most helpful comment

All of your dashboards inherit from Administrate::BaseDashboard, which uses the following method to display resources:

def display_resource(resource)
  "#{resource.class} ##{resource.id}"
end

Assuming you have an Author model with name attribute, you could add this to the AuthorDashboard to overwrite the default:

def display_resource(author)
  author.name
end

All 2 comments

All of your dashboards inherit from Administrate::BaseDashboard, which uses the following method to display resources:

def display_resource(resource)
  "#{resource.class} ##{resource.id}"
end

Assuming you have an Author model with name attribute, you could add this to the AuthorDashboard to overwrite the default:

def display_resource(author)
  author.name
end

That works. Thanks a lot. Found it commented out in dashboards code

Was this page helpful?
0 / 5 - 0 ratings

Related issues

namiwang picture namiwang  路  4Comments

amyin picture amyin  路  4Comments

ghost picture ghost  路  4Comments

trandoanhung1991 picture trandoanhung1991  路  3Comments

rmarronnier picture rmarronnier  路  4Comments