show shows error datatime ruby on rails

0

I have a datetime field and the normal save but render to the show I get this error

This is the error: .to_s ("% d-% m-% Y")

show.html.erb

    <%= @snack.fecha_entrega.to_s("%d-%m-%Y")%>

form

  <div class="form-group">
   <%= label_tag :fecha_entrega, '4.Fecha  y hora de Entrega' %>
  <div class="input-group date datetimepicker" id="">
    <%= f.text_field :fecha_entrega, class: 'form-control deshabilitar ' %>
     <span class="input-group-addon btn btn-default"><span class="fa fa-calendar"></span></span>
   </div>
  </div>

** another different **

 <%= @snack.fecha_entrega.strftime("%d-%m-%Y")%>

    
asked by MIGUEL ANGEL GIL RODRIGUEZ 09.10.2017 в 22:21
source

1 answer

0

Your delivery date is null. You should put:

<%= @snack.fecha_entrega.strftime("%d-%m-%Y") if @snack.fecha_entrega %>

or I would also serve you

<%= @snack.fecha_entrega.try(:strftime, "%d-%m-%Y") %>
    
answered by 10.10.2017 / 20:43
source