Awkward Awkward - 1 year ago 63
Ruby Question

text_field disabled in Ruby on Rails

I have the following code to disable a

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? %>

But when a user is an admin the
just disappears. Does anyone know why this is happening and what I have to do?


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.