https://avo.cool logo
Any idea why params[:global] does not seem to w...
# avo-2
f
Any idea why params[:global] does not seem to work like in this code (resource search is never executed) :
Copy code
ruby
self.search_query = -> do
    if params[:global]
      # Perform global search
      scope.ransack(id_eq: params[:q], nom_cont: params[:q], accountnr_cont: params[:q], m: "or").result(distinct: false)
    else
      # Perform resource search
      scope.ransack(id_eq: params[:q], nom_or_ville_cont: params[:q], accountnr_cont: params[:q], m: "or").result(distinct: false)
    end
  end
m
Thread automatically created by adventurous_seahorse_65114 in #740893011994738751
l
Hey @famous-motherboard-45406 you're on community or pro license?
f
Pro
l
How params look on that Proc when you're searching on the global search?
f
` {"q"=>"", "global"=>"false", "controller"=>"avo/search", "action"=>"show", "resource_name"=>"accounts"}
l
I can't reproduce right now but it seems to me like params from the resource search and not global search
f
Absolutely, this is executed from AccountResource, so global is false and the else branch should be executed. The query I see in the consoel is the global one 😕
l
Aah I understood it the wrong way
I think I know where the issue is
params[:global]
is
"false"
which is a string and
if params[:global]
is a valid condition
Try to cast the
params[:global]
to boolean before using it on the condition
f
This was indeed the problem. I did however take this from the doc. I tried to use the method to_b from ruby/string/facets but I got problems at bundling, so I just tested the string "as it" Thx for your help.
l
Anytime! Try
ActiveModel::Type::Boolean.new.cast(params[:global])
2 Views