How to control model display names in Active Admin
Two practical ways to change which attribute Active Admin uses when rendering a model name: add a display_name method on the model, or change Active Admin’s lookup order to prefer a custom method.

Two practical ways to change which attribute Active Admin uses when rendering a model name: add a display_name method on the model, or change Active Admin’s lookup order to prefer a custom method.

You can customize the list of methods Active Admin tries by setting config.display_name_methods in config/initializers/active_admin.rb.
Define a custom method (for example active_admin_display_name) and make it the first entry in config.display_name_methods to avoid conflicts with other app behavior.
Adjusting the lookup order is useful when your app already has a display_name attribute or when existing to_s/name behaviors are unsuitable.
# Problem Active Admin automatically chooses how to show a model when it needs a human-readable label (for example in dropdowns or resource headings). By default it looks for a few methods on the model and falls back to a generic "ModelName #id" if none match. That can be fine for many apps, but causes issues when your model has a name attribute that needs different formatting in the admin, or when a display_name attribute exists but is sometimes nil.
# Solutions There are two straightforward approaches you can use without changing Active Admin itself.
Use this when you want a single, consistent admin label and you can modify the model directly.
If you can't or don't want to alter the model's existing display_name/name/to_s behavior, change the order of methods Active Admin checks. In config/initializers/active_admin.rb set config.display_name_methods to the array of method names you want Active Admin to try, in order.
This makes active_admin_display_name take precedence. If it returns nil or is not defined, Active Admin moves to display_name, then name, then to_s.
# Why you'd pick each approach
# Example model method (idea only)
# Practical notes
# Short checklist

Originally appeared on Tosbourn – Belfast based Ruby developers . On a recent project we needed Active Admin to show a dropdown box that automatically updated depending on other selections happening on a form. This isn’t supported out of the box by Active Admin, but is quick to add yourself. Bonus points, we get to use
The HTML file input shows “n files selected” when multiple files chosen. Here’s how Stimulus can be used (with or without Rails) to turn that into a list of file names for a better UX https://danielabaron.me/blog/displaying-file-names-for-multi-file-inputs-with-stimulus/

Originally appeared on danielabaron.me RSS Feed . How to build a small Stimulus controller that displays individual file names when users select multiple files, replacing the browser's generic count.
Just released typst-rails, a PDF templating solution for Rage and Rails apps:
https://minitestrails.com/blog/testing-user-registration-rails-minitest/
Open the app view to save this story, compare related coverage, and continue from the same source.