Let's say that I have a two models with this schema:
> create_table "rents", force: :cascade do |t|
t.integer "car_id"
t.datetime "date_start"
t.datetime "date_end"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "cars", force: :cascade do |t|
t.string "name"
t.text "description"
t.integer "price_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Model rent belongs to car and car has_one rent.
How can I add date validation so let's say there exist a rent with car_id: 2 and start_date like 2015-11-01 and date_end like 2015-11-05. I want application to give me error if I want to add another one rent with car_id: 2 and dates where this car is already booked.
How can I do this? Should I use any particular gem or something?