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

前端 未结 7 1119
攒了一身酷
攒了一身酷 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:27

    In your controller's new action, try:

    @user = User.new(:male => true)
    

    Where :male is the attribute you want checked by default on the /users/new pages. This will pass the :male attribute to the view with a value of true, resulting in a checked box.

    0 讨论(0)
提交回复
热议问题