Vitor Vezani
Vitor Vezani

Reputation: 866

How to make a collection_select disabled in rails 4

I wan't to disable a collection_select and already tested the followings code:

<%= 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) %>

None of them work, anyone know why?

Upvotes: 4

Views: 6808

Answers (1)

Monideep
Monideep

Reputation: 2810

From rails documentation

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

Note there is a option attribute before the html options attribute. If you are not defining any options then you have to include a empty braces before defining any html options.

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

Upvotes: 8

Related Questions