Search code examples
ruby-on-rails-3ransack

Ransack OR queries


I want to make a search for all fields that are NULL or have the value of -1 using ransack.

search({:param_name_null => 1 }) 

will give the nulls

search({:param_name_is_any => -1 })

will give the -1s

How do i make an OR between these two using ransack? Thanks


Solution

  • Ransack Issue #290 explains that queries like this contain two separate conditions which need to be specified separately then combined.

    I haven't tested this snippet but it, or something very much like it, should work:

    .search(:m => 'or', :param_name_eq => -1, :param_name_null => true)