rails check_box_tag set checked with default value

后端 未结 6 1398
说谎
说谎 2021-02-18 14:38

I currently have a rails check_box_tag call that looks like

check_box_tag #{name}

I want to include a checked attribute, which I know I can do

6条回答
  •  深忆病人
    2021-02-18 14:44

    If you pass in a value of "1" to the value field, it will pass-on the value of the real state of the checkbox, regardless of the checked default value:

    is_checked = 
    
    check_box_tag :show_defaults, '1', is_checked
    

    (now always reflects user input)

提交回复
热议问题