Getting check_box to default to checked?

I’ve tried this (in a new method/template – so @type doesn’t actually
exist yet):

check_box ‘type’, ‘notify_on_create’, {:checked=>‘true’}

But :checked seems to get swallowed. I’ve also tried setting
notify_on_create to true in the Type model, but that doesn’t work
either. Any way to get the check_box to default to checked?

Thanks,
Joe

Hi Joe:

The check_box helper doesn’t work with :checked => true. Since it is
tailored to work with a specific object and method, the value returned
by that method determines whether or not the checkbox is checked. If the
value is an integer above zero, then the checkbox will be checked.

The check_box_tag helper does accept “:checked => true”, but does not
tie itself directly to an object/method like check_box does.

check_box

check_box_tag

c.

Joe R. MUDCRAP-CE wrote:

I’ve tried this (in a new method/template – so @type doesn’t actually
exist yet):

check_box ‘type’, ‘notify_on_create’, {:checked=>‘true’}

But :checked seems to get swallowed. I’ve also tried setting
notify_on_create to true in the Type model, but that doesn’t work
either. Any way to get the check_box to default to checked?

Thanks,
Joe

On Sun, Oct 15, 2006, Joe R. MUDCRAP-CE wrote:

I’ve tried this (in a new method/template – so @type doesn’t actually
exist yet):

check_box ‘type’, ‘notify_on_create’, {:checked=>‘true’}

But :checked seems to get swallowed. I’ve also tried setting
notify_on_create to true in the Type model, but that doesn’t work
either. Any way to get the check_box to default to checked?

Like someone else said, check_box doesn’t care about that. It’ll use
whatever value is in @type.notify_on_create… I think you see where I’m
going with this…

<% @type.notify_on_create = true -%>
<%= check_box ‘type’, ‘notify_on_create’ %>

I haven’t tested that, but it’ll probably work. :wink:

Ben