excid3 / madmin

A robust Admin Interface for Ruby on Rails apps
https://github.com/excid3/madmin
MIT License
606 stars 66 forks source link

Add collection support for belongs_to fields #230

Closed kaka-ruto closed 1 week ago

kaka-ruto commented 1 week ago

Fixes #156 & https://github.com/excid3/madmin/issues/176

Currently, belongs_to fields don't show all available options in the dropdown. This PR:

Example usage:

class ArticleResource < Madmin::Resource
  attribute :parent_article, collection: -> { Article.all }
end

Before: Static select dropdown with only the current selection visible After: Searchable dropdown showing all available options with filtering

Testing:

  1. Visit any resource edit page with a belongs_to association
  2. Verify the dropdown shows all available options when collection is specified
  3. The collection is searchable
Screenshot 2024-11-20 at 16 51 28