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
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With