为什么要正确禁用表单中的单选按钮,请执行以下操作:
<%= radio_button_tag 'set_creation_radio', 'set_editor', false, disabled: true %>
但这不是(请注意添加了关键字参数checked
):
<%= radio_button_tag 'set_creation_radio', 'set_editor', checked: false, disabled: true %>
在此位置使用断点时,checked
在第一个(即正常工作的)实例中生成以下输出:
0> checked
=> true
而第二个似乎将两个关键字都解释为一个参数:
0> checked
=> {:checked=>true, :disabled=>true}
这是radio_button_tag
的源代码,我不明白为什么在我的示例中checked
会被解释为散列:
def radio_button_tag(name, value, checked = false, options = {})
html_options = { "type" => "radio", "name" => name, "id" => "#{sanitize_to_id(name)}_#{sanitize_to_id(value)}", "value" => value }.update(options.stringify_keys)
html_options["checked"] = "checked" if checked
tag :input, html_options
end