I need to create a new datetime record in my database but first I need to find out is there the same date already saved. The dates inside my database add 4 hours. So, when there is a date which shows it's 2pm, the same date inside database will show it's 6pm. If the dates are the same an alert windows should show.
I'm trying to do something like this but I am not completely sure am I going into right direction:
def create
@appointment_new = Appointment.new(:start_date => params[:start_date],
:end_date => params[:end_date], :doctor_id => params[:doctor_id],
:user_id => params[:user_id])
@appointments = Appointment.all
hour = appointment_new.start_date.hour
minute = appointment_new.start_date.minute
check = false
@appointments.each do |appointment|
{
?????????????
}
end
if(check)
{
if @appointment.save
flash[:success] = "Welcome!"
redirect_to @user
else
alert("failure!")
end
}
else
// do something
end
What do you think? Thanks!