Search code examples
ruby-on-railsransack

Make an OR with ransack


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


Solution

  • Try the following:

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