LuisC LuisC - 1 month ago 7
Ruby Question

check if nested form records are null

Can I check if some record in the nested form is null? I am trying this but it does not work

<%= f.fields_for :detallepromo do |builder| %>
<% if builder.Monto == nil %>

<div class="well center-block">
<div class="form-group">
<h3 class="col-md-5">Promocion Base:</h3>
</div>


<div class="form-group">
<%= builder.label :Monto,"Monto:", class: "control-label col-md-2" %>

<div class="col-md-3">
<%= builder.text_field :Monto, class: "form-control mensaje_fechafinal" %>
</div>
<% end %>
<% end >

Answer

If Monto is a property of your ActiveRecord model, then you can't access it directly on the FormBuilder object.

Try with: <% if builder.object.Monto.nil? %>