Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 422
aharonidan Avatar asked May 14 '13 09:05

aharonidan


People also ask

What is ransack query?

Ransack will help you easily add searching to your Rails application, without any additional dependencies. There are advanced searching solutions around, like ElasticSearch or Algolia. Ransack will do the job for many Rails websites, without the need to run additional infrastructure or work in a different language.

What is ransack gem?

Ransack gem is a very powerful and feature-rich gem used widely by Rails community to implement advanced search capability in a Ruby on Rails application. You can create simple as well as advanced search forms for with this Rails search gem.


1 Answers

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)
like image 77
Josh Rumbut Avatar answered Oct 16 '22 09:10

Josh Rumbut