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
Hi,
I really like your approach here. I hope you have time to develop it further.
I hit an issue when running with postgres. The LIKE query fails for boolean or integer.
I'm guessing that you're testing on mysql or sqlite and they're more forgiving...
This fixes the issue for me at least:
def filtered_resources(resources)
@filterable_attributes = AdministrateFilterable::FiltererService.filter_attributes(dashboard, new_resource)
filter_params = params[resource_name]
return resources if filter_params.blank?
filter_params.each do |key, value|
next unless resources.column_names.include?(key.to_s) && value.present?
attribute_type = new_resource.class.attribute_types[key].type
case attribute_type
when :boolean
boolean_value = ActiveRecord::Type::Boolean.new.cast(value)
resources = resources.where(key => boolean_value)
when :integer
integer_value = value.to_i
resources = resources.where(key => integer_value)
else
sanitized_query = ActiveRecord::Base.send(:sanitize_sql_array, ["#{key} LIKE ?", "%#{value}%"])
resources = resources.where(sanitized_query)
end
end
resources
end
The text was updated successfully, but these errors were encountered:
Hi,
I really like your approach here. I hope you have time to develop it further.
I hit an issue when running with postgres. The LIKE query fails for boolean or integer.
I'm guessing that you're testing on mysql or sqlite and they're more forgiving...
This fixes the issue for me at least:
The text was updated successfully, but these errors were encountered: