Topic: Auto Set a Checkbox to true [SOLVED]

i have my form in a partial so i am using the same form for add and edit.

but on the add page i want to have some checkboxes marked as default but if they are not checked on the edit page i don't want to re checked them

            %td{:scope => "row"}= f.label t(:days_of_the_week)
            %td{:colspan => "3"}
              = t(:monday)
              = f.check_box :monday, :checked
              = t(:tuesday)
              = f.check_box :tuesday
              = t(:wednesday)
              = f.check_box :wednesday
              = t(:thursday)
              = f.check_box :thursday
              = t(:friday)
              = f.check_box :friday
              = t(:saturday)
              = f.check_box :saturday
              = t(:sunday)
              = f.check_box :sunday

Last edited by moiseszaragoza (2012-07-13 10:06:41)

Re: Auto Set a Checkbox to true [SOLVED]

In the new action on your controller just set the default values you want on the model:

def new
    @model =
    @model.monday = true

Re: Auto Set a Checkbox to true [SOLVED]

Thanks you that helps.