日期验证比方说,我有两个型号,这个模式:订票
> 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
型号租金属于汽车和汽车HAS_ONE租金。
如何添加日期验证让我们说存在一个待租car_id:2和START_DATE像2015年11月1日和DATE_END像2015年11月5日。我想申请给我的错误,如果我想与car_id再添一个租金:2和日期,其中这款车已经被预订。
我该怎么做?我应该使用任何特定的宝石或什么?
模型验证看来,你只需要一个简单的自定义在这里验证。 –
看一看这篇文章http://stackoverflow.com/questions/9839260/dealing-with-time-periods-in-rails-3-1和自定义您的需要。 – Pavan