Hi Tim,

I think a good solution would be using some custom SQL:
  search = params[:search]
  @plans = Plan.regional(session[:region_id].to_i).where("name LIKE ? OR
last_name LIKE ? OR first_name LIKE ?",
"%#{search}%","%#{search}%","%#{search}%")

You could also create a nice scope and then use it like:
  @plans = Plan.regional(session[:region_id].to_i).search(params[:search])

Warm regards,
Ignacio


El 08/02/14 14:14, Tim Griffin escribió:
> Hi all;
> 
> Bit of an urgent plea here to help me understand how to adapt search
> parameters in a Hobo Index function to satisfy PostgreSQL's strong typing. 
> 
> I have a Plan class:
> 
>     plan_no     :decimal, :default => 0, :precision => 12, :scale => 3  
> # to accommodate 123456789.999
>     clsr             :integer       
> 
> In my /index/ method, I include these in search scopes:
> 
>     scopes = {                                                          
>     
>       :search => [ params[:search], :plan_no, :clsr ]
>     }
> 
> Then, I search:
> 
>     @plans = Plan.regional(session[:region_id].to_i).apply_scopes(scopes)
> 
> 
> But, Postgres is very unhappy about comparing the text I type in the
> Search box with the decimal and integer fields /plan_no/ and /clsr:/
> /
> /
> HINT:  No operator matches the given name and argument type(s). You
> might need to add explicit type casts.
> : SELECT  "plans".* FROM "plans" WHERE (plans.region_id = 1) AND
> (((plans.plan_no ILIKE '%4430%') OR (plans.clsr ILIKE '%4430%'))) DESC
> LIMIT 40 OFFSET 0
> /
> PG::UndefinedFunction: ERROR:  operator does not exist: numeric ~~* unknown
> /
> LINE 1: ... WHERE (plans.region_id = 1) AND (((plans.plan_no ILIKE '%44...
> 
> Can anyone enlighten me on how to work those suggested casts into the
> search process without resorting to preparing my own SQL statement? This
> seems doubly difficult given that both fields are of different types,
> and I never know whether someone is searching by plan_no or by clsr!
> 
> Many thanks,
> Tim
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to