You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To support a boolean field that is used as having a trinary value, I have had to override the filter_instructions_for method (see below). This is because a nil value is discarded.
# Override ActionSet filter_instructions_for method to modify filtering behavior.
def filter_instructions_for(set)
filter_params_hash = super
# Allow `nil` values to be passed as meaningful filters on boolean fields
filter_params.select { |_, v| v.include? 'nil' }.each do |k, v|
modified_nil_value = nil if v.instance_of?(String) && v == 'nil'
modified_nil_value = manipulate_trinary_boolean_array(v) if v.instance_of?(Array)
filter_params_hash[k] = modified_nil_value if modified_nil_value
end
filter_params_hash
end
def manipulate_trinary_boolean_array(array)
array.map do |b|
next nil if b == 'nil'
ActiveModel::Type::Boolean.new.cast(b)
end
end
The text was updated successfully, but these errors were encountered:
To support a boolean field that is used as having a trinary value, I have had to override the
filter_instructions_for
method (see below). This is because anil
value is discarded.The text was updated successfully, but these errors were encountered: