我正在尝试在我的表中添加一个禁用的下拉框,我最终将其作为条件。 但是,在运行时似乎没有将禁用添加到行中。
如果我检查页面中的元素,手动添加已禁用的工作,但不会在运行时添加。
= f.fields_for(:targets, qualification.target_for(@grandfather.user)) do |builder|
%tr
%td
= builder.select :completed, qualification.level_options.map{|o| [o,o]}, :disabled => "disabled"
= builder.hidden_field :qualification_id, :value => qualification.id
= builder.hidden_field :id
答案 0 :(得分:3)
查看Rails的Form Helper API
APIselect(object, method, choices, options = {}, html_options = {})
它正在向选项添加:disabled => "disabled"
,而不是html_options。这是要使用的代码(注意options参数的空哈希):
builder.select(:completed, qualification.level_options.map{|o| [o,o]}, {}, {:disabled => "disabled"})