I would like to set a rails form text_field property to read only when the model already contains a value.
Here is my code
<%= f.text_field :domain, class="span4", readonly: "true" %>
I want to avoid doing something verbose like:
<%if @model.domain.empty? %>
<%= f.text_field :domain, class="span4"%>
<%else%>
<%= f.text_field :domain, class="span4", readonly: "true" %>
<%end%>
Thanks!
<%= f.text_field :domain, class="span4", :disabled => !@model.domain.blank? %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.