Use Ransack with radio buttons for boolean values


I’m trying to search for active and non active users. These radio
work just fine except that it didn’t reselect itself after the form has
been submitted. So, what should I do to ensure it will be selected just
like how my text field populated automatically after the form has been

= search_form_for @q do |f|
= f.radio_button :is_active_false, 1
= f.radio_button :is_active_true, 1

Thanks in advance.

Hi Amree,

Try something like this:

= f.radio_button :is_active_false, 1, :checked =>
= f.radio_button :is_active_true , 1, :checked => @search.is_active_true

Let me know if this works for you.

Also, aren’t you able to check both buttons at the same time, given that
the have different name attribute from each other?

Em domingo, 20 de novembro de 2011 07h42min39s UTC-2, Amree escreveu:


have you tried the :checked option?

That was the only solution for me.
If anyone have any better solution, please post here.

Lucca Mordente

I use a drop down box as then I can select true, false or don’t care

= :my_bool_field_eq, options_for_select([false, true]),
include_blank: true