Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 860
Vitor Vezani Avatar asked Oct 28 '25 18:10

Vitor Vezani


1 Answers

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" }) %>
like image 65
Monideep Avatar answered Oct 31 '25 07:10

Monideep