https://avo.cool logo
hey guys, one of my clients has an old version ...
# avo-3
n
hey guys, one of my clients has an old version of Avo:
Copy code
gem "avo", "3.15.7"
gem "avo-advanced", "3.15.7"
for some reason, this:
Copy code
ruby
class Avo::Resources::CommunityUser < Avo::BaseResource
  self.includes = [ :community, :user, :team ]
  self.model_class = ::Community::User

  def fields
    field :id, as: :id
    field :community, as: :belongs_to, searchable: true, can_create: false
    field :user, as: :belongs_to, can_create: false, searchable: true, attach_scope: -> {
      query.not_deleted
    }
    field :status, as: :select, enum: ::Community::User.statuses.keys
    field :role, as: :select, enum: ::Community::User.roles.keys
    field :team, as: :belongs_to, can_create: false
    field :team_role, as: :select, enum: ::Community::User.team_roles.keys
    field :created_at, as: :date_time, hide_on: %i[edit new]
  end
end
neither the community nor the user are being able to be searched; the
search controller
is being called, but no responses is coming back. if you use the global search to search for a user, he shows any idea ?
m
Thread automatically created by Roc Khalil in #1138182212655788054
l
Hi @narrow-electrician-89982 how does the other resources look?
Specialy the self.search configuration
n
Copy code
ruby
class Avo::Resources::CommunityCommunity < Avo::BaseResource
  # self.includes = []
  # self.attachments = []
  self.model_class = ::Community::Community
  self.search = {
    query: -> { query.ransack(id_eq: params[:q], name_cont: params[:q], m: "or").result(distinct: false) }
  }

  def fields
....
Copy code
ruby
module Avo
  module Resources
    class User < Avo::BaseResource
      self.devise_password_optional = true
      self.includes = [ :avatar, :referred_by, image_attachment: :blob ]
      self.title = :email
      self.search = {
        query: -> {
          query.ransack(email_cont: params[:q], first_name_cont: params[:q], m: "or").result(distinct: false)
        }
      }
l
CommunityCommunity?
n
yes, it's a namespace
l
Ok, is there a single named resource called community?
n
Copy code
ruby
module Community
  def self.table_name_prefix
    "community_"
  end
end


class Community::Community < ApplicationRecord
end
l
On the belongs to try use_resource: the doble community one
I'm on phone rn, sorry about the snippets =))
Actually about the lack of them =))
n
no worries !!
Copy code
ruby
field :community, as: :belongs_to, searchable: true, can_create: false, use_resource: ::Community::Community
still nothing shows up
l
With the whole avo namespace
l
Avo::Resources::...
n
Avo::Resources::CommunityCommunity
same
anyway, not urgent today - I can fix it tomorrow
go and enjoy your Sunday! we'll figure it out tomorrow
l
It's all right, put a debugger in both community and user search configuration and confirm if those queries are being called
n
they are not
that's the weird thing
l
Got.it
To figure it out I would bundle open avo and put a debugger on the avo search controller then go step by step
n
perfect
i'll try it
@loud-jewelry-99127 here's the fix:
Copy code
ruby
  def search?
    index?
  end
in the policy
didn't know that
search
was a thing
l
Aaaah
Yes!
n
but this is weird
why it's working in the global search ( header ) but not in the comoponent ?
l
Didn't get the chance to work on it
n
makes sense 🤝
thanks a lot for the hard work !!
l
Anytime!