validate 24 hours rails

0
validate :prueba

def prueba
  self.hora_pedido = Time.zone.now.strftime("%Y-%m-%d-%H:%M:%S" )

  if ( hora_entre - ( 60 * 60 * 24 ) ) < ( hora_pedido )
    errors.add(:hora_entre, "hora  no válida")
  end
end

validate

hora_entre is chosen per form and hora_pedido per self if not, that does not give me, I want to validate if it is less than 24 Hours and I get an error.

hora_delivery is hora_entre

Log

    
asked by juan gomez 20.06.2017 в 22:10
source

1 answer

0

To show the errors in your view, you should look for errors that have been generated in the object (e.g. @reunion ) and, if so, display them in your view.

For example, in your view new.html.erb you could add the following code 1 :

<% if @reunion.errors.any? %>
  <div>
    Se han encontrado los siguientes errores:
    <ul>
      <% @reunion.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
    </ul>
  </div>
<% end %>

You must define the place on the page where you want this message to be displayed (usually it is at the top of the form) and style it according to the design of your site.

1 I'm assuming that the object you want to create is called @reunion , but replaces the variable with the one defined in the action create of the controller.

    
answered by 21.06.2017 / 16:41
source