LuisC LuisC - 1 year ago 78
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 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" %>
<% end %>
<% end >

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download