如何在rails 4中禁用collection_select

时间:2014-05-23 00:20:15

标签: ruby-on-rails ruby

我不想禁用collection_select并且已经测试了以下代码:

<%= f.collection_select(:categoria_id, Categoria.order(:descricao), :id, :descricao,{ class: "form-control", :disabled => "disabled" }) %>
<%= f.collection_select(:categoria_id, Categoria.order(:descricao), :id, :descricao,{ class: "form-control", :disabled => true }) %>
<%= f.collection_select(:categoria_id, Categoria.order(:descricao), :id, :descricao, class: "form-control", :disabled => "disabled") %>
<%= f.collection_select(:categoria_id, Categoria.order(:descricao), :id, :descricao, class: "form-control", :disabled => true) %>

他们都不工作,有谁知道为什么?

1 个答案:

答案 0 :(得分:4)

来自rails文档

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) public

请注意,html选项属性之前有一个选项属性。如果您没有定义任何选项,则必须在定义任何html选项之前包含空括号。

<%= f.collection_select(:categoria_id, Categoria.order(:descricao), :id, :descricao,{},{ class: "form-control", :disabled => "disabled" }) %>