我试图在我的表中添加一个禁用的下拉框,我最终将使其成为条件。然而,disabled在运行时似乎没有添加到该行。
如果我检查页面中的元素,手动添加disabled工作,但它不会在运行时添加。
= 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
查看Rails的Form Helper API
select(object, method, choices, options = {}, html_options = {})
将:disabled => "disabled"
添加到选项中,而不是html_options。这是要使用的代码(注意options参数的空散列):
builder.select(:completed, qualification.level_options.map{|o| [o,o]}, {}, {:disabled => "disabled"})