text_field disabled in Ruby on Rails

ruby, ruby-on-rails

Solution

Assuming that `is_admin?` returns `true` or `false`, you can simply do

<%= f.text_field :nome, class: "form-control", disabled: !is_admin? %>

Currently, the if condition i.e., `if not is_admin?` is applied on the entire text field, which results in text field disappearance when `is_admin?` returns `true` and when the condition returns `false` text field is displayed.

Problem

I have the following code to disable a `text_field` when a user is not an admin and it is working fine: ``` <div class="form-group"> <%= f.label :nome, "Genero" %> <%= f.text_field :nome, class: "form-control", disabled: true if not is_admin? %> </div> ``` But when a user is an admin the `text_field` just disappears. Does anyone know why this is happening and what I have to do?

Original source