I have a table with a column is_active which takes boolean parameter . So I want to list only the rows which have is_active as true by default unless user searches for the false value rows . Is there any way that I can achieve this . I tried "conditions_for_collection " method but that shows only true rows and when you search for false it shows no rows found . I tried condition_for_is_active_column also but no luck .
def conditions_for_collection
['is_active = ?', true]
end
def condition_for_is_active_column(column, value, like_pattern)
case value
when 'true'
['is_active = ?', true]
when 'false'
['is_active = ?', false]
end
end
try to help you. Have you tried using default_scope? Docs here: https://apidock.com/rails/ActiveRecord/Base/default_scope/class And you can use ActiveModel::Type::Boolean.new.cast(value) Instead of case "true" Example:
Bollean cast format: 1 => true, "true" => true, nil => false. And other. Hope, it is help you