From f9b5de290e01cf5e74f0807ea40b26f244a94b0c Mon Sep 17 00:00:00 2001 From: David Parker Date: Wed, 7 Feb 2018 16:25:12 -0700 Subject: [PATCH] Use the namespace for the active admin resource. This allows the namespace to be somewhere other than `:admin`. --- README.md | 19 ++++++++++++++++++- .../select_input_extension.rb | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dcf6139..fe76b19 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ based on the input attribute name, you can pass an object with a end ``` -#### Mutlple Options Endpoints per Resource +#### Multiple Options Endpoints per Resource A single ActiveAdmin resource can define multiple options endpoints: @@ -167,6 +167,23 @@ To specify which collection to use, pass an object with a end ``` +#### Querying Multiple Attributes + +ActiveAdmin Searchable Select querying is performed by Ransack. As such, you can +build your query in a way that it can query multiple attributes at once. + +```ruby + ActiveAdmin.register User do + searchable_select_options(scope: User.all, + text_attribute: :username, + filter: lambda do |term, scope| + scope.ransack(email_or_username_cont: term).result + end) + end +``` + +In this example, the `all` scope will query `email OR username`. + #### Passing Parameters You can pass additional parameters to the options endpoint: diff --git a/lib/activeadmin/searchable_select/select_input_extension.rb b/lib/activeadmin/searchable_select/select_input_extension.rb index 01e024c..6f0d76e 100644 --- a/lib/activeadmin/searchable_select/select_input_extension.rb +++ b/lib/activeadmin/searchable_select/select_input_extension.rb @@ -45,7 +45,7 @@ def collection_from_options def ajax_url return unless options[:ajax] - template.polymorphic_path([:admin, ajax_resource_class], + template.polymorphic_path([template.active_admin_namespace.name, ajax_resource_class], action: option_collection.collection_action_name, **ajax_params) end