๐ BIG NEWS ๐ โฆ Avo 4 has officially SHIPPED โฆ ๐ the beta is over, 4.0 is here โฆ ๐ ๏ธ build admin panels, dashboards & internal tools at light speed โฆ โญ you are visitor #1,136,930 โฆ ๐ tell a friend โฆ best viewed in Ruby on Rails โฆ ๐ click here to see what’s new โฆ
Searchable Associations
Let users search through associated records when assigning relationships. Find the right record fast, even in large datasets.
# $15/mo
gem "avo-advanced_search"
Let people find the right record by typing a few letters, instead of
scrolling a dropdown with a thousand options in it. Searchable Associations
turns the standard <select>
on an Avo association field into a search-as-you-type picker: set
searchable: true
on a belongs_to,
has_one, or
has_many
field and the picker queries records as the user types. It reuses the
self.search
block already defined on the target resource, so most pickers light up with
no extra config.
# app/avo/resources/project.rb
class Avo::Resources::Project < Avo::BaseResource
def fields
# Boolean form: reuse the target resource's self.search
field :user, as: :belongs_to, searchable: true
# Hash form: full control over the query and each row
field :members, as: :has_many, searchable: {
query: -> { query.ransack(name_cont: q).result },
item: -> { { title: record.name, description: record.email } },
enabled: -> { current_user.admin? }
}
end
end
When you need more control, pass a hash instead of true:
a query:
proc runs as the user types so you decide exactly which records match,
item:
shapes each row's title
and description,
and enabled:
can switch searchable mode on per user, falling back to a plain select for
everyone else. Polymorphic belongs_to
works too, with each type routing to its own resource's search. That is a
search input wired to your data, not a feature you build, test, and keep
working as your tables grow.
What you get
-
Search-as-you-type picker that replaces the standard
<select>on association fields -
Works on
belongs_to,has_one, andhas_manyfields, including polymorphicbelongs_to -
Boolean form (
searchable: true) reuses theself.searchblock already defined on the target resource -
Hash form takes a
query:proc that runs as the user types, so you decide exactly which records match -
item:proc to render each row'stitleanddescriptionin the dropdown -
enabled:boolean or proc to turn searchable mode on or off per user, falling back to a plain select -
Show default results before any typing by branching on
q.blank?inside thequery:proc
Why it pays off
-
Drop
searchable: trueon a field and a usable picker ships this afternoon, instead of building autocomplete, debouncing, and a JSON endpoint over a sprint. - It reuses the resource search you already configured, so one definition powers every picker pointing at that record.
- It is built for the breadth of real apps, large tables, polymorphic targets, per-user gating, the cases a quick internal build tends to skip.
- Every Avo release makes it better: the picker gains improvements and keeps working through upgrades, without you patching it.
# included in
# ready to ship?
You ship it this afternoon. We keep it solid for years.