add checkbox with simple_form without association with model?

后端 未结 6 1467
北荒
北荒 2020-12-29 03:49

How I can add checkbox with simple_form without association with model? I want to create checkbox which will handle some javascript events, but don\'t know? Maybe I miss som

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 04:06

    The command proposed by huoxito does not work (at least not in Rails 4). As far as I figured out the error is caused by Rails trying to look up the default value for :custom_field, but because this field does not exists this lookup fails and an exception is thrown.

    However, it works if you specify a default value for the field using the :input_html parameter, e.g. like this:

    = f.input :custom_field, :as => :boolean, :input_html => { :checked => "checked" }
    

提交回复
热议问题