From 77a3a54ea5e824950858486ff9efa9d1d65f1f91 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Tue, 10 Oct 2023 20:01:10 +0300 Subject: [PATCH 1/3] improvement: dynamic filters --- docs/3.0/dynamic-filters.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/3.0/dynamic-filters.md b/docs/3.0/dynamic-filters.md index fb3d345f..421639df 100644 --- a/docs/3.0/dynamic-filters.md +++ b/docs/3.0/dynamic-filters.md @@ -7,12 +7,12 @@ license: advanced The Dynamic filters make it so easy to add multiple, composable, and dynamic filters to the view. -The only thing you need to do is add the `filterable: true` attribute to the fields you need to filter through. +The first thing you need to do is add the `filterable: true` attribute to the fields you need to filter through. We use `ransack` behind the scenes so it's essential to configure the `ransackable_attributes` list to ensure that every filterable field is incorporated within it. -```ruby{6-8} -class Avo::Resources::Project < Avo::BaseResource - self.title = :name +:::code-group +```ruby{4-6} [Fields] +class Avo::Resources::Project < Avo::BaseResource def fields field :name, as: :text field :status, as: :status, filterable: true @@ -22,6 +22,15 @@ class Avo::Resources::Project < Avo::BaseResource end ``` +```ruby{3} [Ransackable attribures] +class Project < ApplicationRecord + def self.ransackable_attributes(auth_object = nil) + ["status", "stage", "country"] + end +end +``` +::: + This will make Avo add this new "Filters" button to the view of your resource. When the user clicks the button, a new filters bar will appear below enabling them to add filters based on the attributes you marked as filterable. From d9b8444db98dd884dbbb433dd135912066ee7d28 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Wed, 11 Oct 2023 09:41:07 +0300 Subject: [PATCH 2/3] Update docs/3.0/dynamic-filters.md --- docs/3.0/dynamic-filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/3.0/dynamic-filters.md b/docs/3.0/dynamic-filters.md index 421639df..e8c880c8 100644 --- a/docs/3.0/dynamic-filters.md +++ b/docs/3.0/dynamic-filters.md @@ -22,7 +22,7 @@ class Avo::Resources::Project < Avo::BaseResource end ``` -```ruby{3} [Ransackable attribures] +```ruby{3} [Ransackable attributes] class Project < ApplicationRecord def self.ransackable_attributes(auth_object = nil) ["status", "stage", "country"] From 0324b0d97d722400eb39929b42806e91a799fe12 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 11 Oct 2023 11:36:04 +0300 Subject: [PATCH 3/3] super ransackable attributes --- docs/3.0/dynamic-filters.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/3.0/dynamic-filters.md b/docs/3.0/dynamic-filters.md index 421639df..5e636cbc 100644 --- a/docs/3.0/dynamic-filters.md +++ b/docs/3.0/dynamic-filters.md @@ -22,12 +22,21 @@ class Avo::Resources::Project < Avo::BaseResource end ``` -```ruby{3} [Ransackable attribures] +```ruby{3,9,12} [Ransackable attribures] class Project < ApplicationRecord def self.ransackable_attributes(auth_object = nil) ["status", "stage", "country"] end end + +# Or + +# https://activerecord-hackery.github.io/ransack/going-further/other-notes/#authorization-allowlistingdenylisting +class Project < ApplicationRecord + def self.ransackable_attributes(auth_object = nil) + super + end +end ``` :::