hi im new in rails and starting to develop my application which is a
online reservation im just wondering if there is a way in Ruby on
rails to group a validation
ei. i want to validate the uniqueness of date first in the database
and check what are the timeStart and endTime entries in that
particular date and validate its uniqueness(timeStart and endTime)
base on the date? is it possible in validation or do i have to make a
controller or method for it?
to sum up my application can book a reservation in a same date but not
in a same date and time
sorry for my bad english my Reservation database is:
0 id INTEGER 1 1
1 lname varchar(25 1 0
2 fname varchar(25 1 0
3 contactnum integer 1 0
4 email varchar(10 1 0
5 date date 1 '2012-03-0 0
6 timeStart time 1 '---
:hour 0
7 timeEnd time 1 '---
:hour 0
8 numGuest integer 0 5 0
9 totalCost decimal(2) 0 0
10 confirm boolean 0 'f' 0
11 created_at datetime 0 0
12 updated_at datetime 0 0
ei. i want to validate the presence of date first in the database
and check what are the timeStart and endTime entries in that
particular date and validate its uniqueness(timeStart and endTime)
base on the date? is it possible in validation or do i have to make a
controller or method for it?
If you are building a “serious” reservation system and you do never
ever want to promise the same resource to 2 different users at the
same timeslot, you better understand that problem.
If your timeStart and endTime are intended as “times in a day”
and not an absolute time in history, you might use my ‘relativity’ gem
You might be better to use datetime column types rather than a
separate date and time. Then you will just need to check the
uniqueness of the datetime values. You can easily then extract the
date and time separately for display purposes.
It also has a DayTimeRange that may be useful for what you are trying
to do. If you use a standardized separator you could even write an
equality or overlap comparator for DayTimeRange class.