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
It is chosen by form and hora_pedido
if self
not, it does not give me, I want to validate if it is less than 24 hours and I get an error.
delivery_time is between_time
To display the errors in your view, you must look for any errors that have been generated in the object (eg
@reunion
) and, if so, display them in your view.For example, in your view
new.html.erb
you could add the following code 1 :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 the object you want to create is called
@reunion
, but substitute the variable for whatever is defined in thecreate
controller action.