๐ŸŽ‰ 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  โœฆ 

Back to pricing
Gemfile

Searchable Associations

Add to your plan

Let users search through associated records when assigning relationships. Find the right record fast, even in large datasets.

# $15/mo

1 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, and has_many fields, including polymorphic belongs_to
  • Boolean form (searchable: true) reuses the self.search block 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's title and description in 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 the query: proc

Why it pays off

  • Drop searchable: true on 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.