I know that this is a problem from Ransack but I still not find solution. When I search and pass parameter as 't' or 'f' it automatically convert to Boolean and my search is wrong.
I found the same bug, in the README it refers there is a automatic conversion for boolean values on a string or integers, but it also seems to do the same for t and f
In Rails 3 and 4, if the true value is being passed via url params or some other mechanism that will convert it to a string, the true value may not be passed to the ransackable scope unless you wrap it in an array (i.e. activated: ['true']). Ransack will take care of changing 'true' into a boolean. This is currently resolved in Rails 5 馃槂
However, perhaps you have user_id: [1] and you do not want Ransack to convert 1 into a boolean. (Values sanitized to booleans can be found in the constants.rb). To turn this off globally, and handle type conversions yourself, set sanitize_custom_scope_booleans to false in an initializer file like config/initializers/ransack.rb:
Ransack.configure do |c| c.sanitize_custom_scope_booleans = false endTo turn this off on a per-scope basis Ransack adds the following method to ActiveRecord::Base that you can redefine to selectively override sanitization:
ransackable_scopes_skip_sanitize_argsAdd the scope you wish to bypass this behavior to ransackable_scopes_skip_sanitize_args:
def ransackable_scopes_skip_sanitize_args [:scope_to_skip_sanitize_args] end
https://github.com/activerecord-hackery/ransack#using-scopesclass-methods
it because this https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/constants.rb#L26
All values in TRUE_VALUES and FALSE_VALUES will automatically convert to Boolean if option type is :boolean
@truonglocbinh93 can this be closed?
@seanfcarroll Yes It can be close, thank you
Closing.
Most helpful comment
I found the same bug, in the README it refers there is a automatic conversion for boolean values on a string or integers, but it also seems to do the same for
tandfhttps://github.com/activerecord-hackery/ransack#using-scopesclass-methods