Ruby-on-rails – Make an OR with ransack

ransackruby-on-rails

A basic questiĆ³n, but I couldn't find something clear in the project page or the wiki. I have the following code:

field = "secre"
Position.search( {:description_cont => field, :code_cont => field}).result(:distinct => true).to_sql
 => "SELECT DISTINCT `positions`.* FROM `positions`  WHERE ((`positions`.`description` LIKE '%secre%' AND `positions`.`code` LIKE 0))"

But my query should be like:

 => "SELECT DISTINCT `positions`.* FROM `positions`  WHERE ((`positions`.`description` LIKE '%secre%' OR `positions`.`code` LIKE 0))"

Any help would be appreciated. Thanks in advance

Best Answer

Try the following:

Position.search( {:description_or_code_cont => field}).result(:distinct => true).to_sql
Related Topic