Awkward Awkward - 5 months ago 31x
Ruby Question

text_field disabled Ruby on Rails

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

But when a user is an admin the text_field just despair, anyone one 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.