在表单上设置 Default: Disabled 时,某些布尔选项会被禁用?

When setting Default: Disabled on a form, some Boolean options get disabled?

我有以下生成表单的行。调用时,控制器在某些情况下将@disabled 设置为 true,在其他情况下设置为 false。

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled }, url: wizard_path, method: :put do |f|

在某些页面上,我有一个使用布尔选项的 select 语句。

= f.input :accommodation, as: :select, collection: yes_no

即调用以下辅助函数作为集合

  def yes_no
[
  ['Yes', true ],
  ['No', false ]
]
end

@disabled设置为false时,simple_form去渲染false选项,好像是禁用了。我不确定如何绕过这个布尔值冲突以在下拉列表中生成 true 和 false 选项,同时还允许 @disabled 禁用整个表单(如果适用)

SimpleForm 和 Rails 之间的已知问题:https://github.com/plataformatec/simple_form/issues/1257

tonywok 的回答目前似乎是一个有效的解决方法:https://github.com/plataformatec/simple_form/issues/1257#issuecomment-119226834

改变

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled }, url: wizard_path, method: :put do |f|

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled, readonly: nil }, url: wizard_path, method: :put do |f|