How can I make a check box default to being “checked” in Rails 1.2.3?

前端 未结 7 1149
攒了一身酷
攒了一身酷 2021-02-06 21:38

How can I make a check box default to being \"checked\" when it is initially displayed?

I\'ve not found a \"Rails\" way to do this (that works) so I did it with JavaScr

7条回答
  •  温柔的废话
    2021-02-06 22:20

    Rails 3.x

    = form_for(@user) do |f|
      = f.check_box :subscribe, {checked: true, ...}
    

    This sets the checked state to true and should work fine. Note the ruby 1.9.x syntax of the hash, for ruby 1.8.x use hash tag format {:checked => true, ...}

提交回复
热议问题