Skip to content

Commit 1ab4af7

Browse files
committed
- avo: ransack -> arel
1 parent d7ed2f8 commit 1ab4af7

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

app/avo/resources/cloud.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ class Avo::Resources::Cloud < Avo::BaseResource
33

44
self.search = {
55
query: -> {
6-
query.ransack(
7-
participant_full_name_cont: params[:q],
8-
participant_email_cont: params[:q],
9-
m: "or"
10-
).result(distinct: false)
11-
}
6+
query.joins(:participant)
7+
.merge(Participant.search(params[:q]))
8+
},
9+
item: -> do
10+
{
11+
title: "#{record.id} (#{record.participant.full_name}#{record.participant.email})"
12+
}
13+
end
1214
}
1315

1416
class BulkDelete < Avo::BaseAction

app/avo/resources/invitation.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ class Avo::Resources::Invitation < Avo::BaseResource
33

44
self.search = {
55
query: -> {
6-
query.ransack(
7-
participant_full_name_cont: params[:q],
8-
participant_email_cont: params[:q],
9-
m: "or"
10-
).result(distinct: false)
11-
}
6+
query.joins(:participant)
7+
.merge(Participant.search(params[:q]))
8+
},
9+
item: -> do
10+
{
11+
title: "#{record.id} (#{record.participant.full_name}#{record.participant.email})"
12+
}
13+
end
1214
}
1315

1416
def fields

app/avo/resources/participant.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ class Avo::Resources::Participant < Avo::BaseResource
44

55
self.search = {
66
query: -> {
7-
query.ransack(
8-
full_name_cont: params[:q],
9-
email_cont: params[:q],
10-
m: "or"
11-
).result(distinct: false)
7+
query.merge(Participant.search(params[:q]))
128
}
139
}
1410

app/models/participant.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Participant < ApplicationRecord
1515

1616
scope :without_picked_cloud, -> { where.missing(:picked_cloud) }
1717
scope :without_invitations, -> { where.missing(:invitations) }
18+
scope :search, ->(q) { where(arel_table[:full_name].matches("%#{q}%").or(arel_table[:email].matches("%#{q}%"))) }
1819

1920
before_create do
2021
self.access_token ||= Nanoid.generate(size: 6)

0 commit comments

Comments
 (0)