Search code examples
ruby-on-railsrubyransack

Submit nil as value for f.check_box when checked with ransack gem


I think I am just using the rails check_box form helper incorrectly. Here is the relevant part of the form. I am using ransack but I don't think it makes a difference here:

<div class="form-group col-sm-4">
  <%= f.label :date_closed_eq, "Only Open Cases" %><br>
  <%= f.check_box(:date_closed_eq, {}, nil, false) %>
</div>

When the check box is checked and the form is submitted here is the parameters hash:

Parameters: {"utf8"=>"✓", "q"=>{"date_closed_eq"=>"on"}, "commit"=>"Search"}

So for some reason "on" is passed through. But I want it to be nil. Not sure what I am missing here.

I did notice this similar question but that question never had an answer, and my attempts to apply it were not successful.

Another similar question but again no accepted answer and I am still having trouble.


Solution

  • I was using the wrong predicate:

      <%= f.check_box(:date_closed_null, {}, true, false) %>