Ruby on rails Rails约会网站-阻止某些时间段/天
我被要求建立一个网站,用户可以预约汽车试驾 日历不限于10天,所以我不能事先指定日期。汽车经销商应该有能力阻止特定的日期或时间段 我设计了一个Testdrive表,看起来像这样:Ruby on rails Rails约会网站-阻止某些时间段/天,ruby-on-rails,database-design,database-schema,Ruby On Rails,Database Design,Database Schema,我被要求建立一个网站,用户可以预约汽车试驾 日历不限于10天,所以我不能事先指定日期。汽车经销商应该有能力阻止特定的日期或时间段 我设计了一个Testdrive表,看起来像这样: Testdrive --------- - id - user_id - date - timeslot - client_title - client_name - client_firstname - client_company - client_street - client_house_nr - client
Testdrive
---------
- id
- user_id
- date
- timeslot
- client_title
- client_name
- client_firstname
- client_company
- client_street
- client_house_nr
- client_postal_code
- client_city
- client_email
- client_phone
- client_mobile
然而,我现在不确定如何对“阻塞”的插槽/日期进行建模。我正在考虑制作另一个类似“TestdriveDate”之类的表格,但我会将日历限制在该表格中的内容上。。。我不希望经销商必须启用每天/时隙,也不希望在我的数据库中放入那么多数据。所以,我想我应该有类似“BlockedDate”或“BlockedTimeSlot”的东西。然而,在这种情况下,我必须对照此表检查前端列表中的每个日期。。这也让人感觉不对劲
我想“封锁日期”的方法是最好的方式?正在寻找建模方面的帮助,以便它对我作为开发人员和我的用户(汽车经销商)有用。这种方法怎么样 块
- 日期
- 时隙
- 块标识
- 用户id
- 客户名称
- 客户名称
- 客户名
- 客户公司
- 客户街
- 客户号
- 客户邮政编码
- 客户城市
- 客户电子邮件
- 客户电话
- 移动客户端
模块
模型可由汽车经销商或预约创建
例如,可以有一个id为1的块。如果有一个TestDrive具有block_id=1
,则这是一个约会。如果找不到具有block_id=1
的TestDrive,则这只是一个阻塞的插槽
因此块有一个:test\u drive
,TestDrive属于:块
。TestDrive必须与块关联,但块不能有TestDrive(零对多关系)执行以下操作:
#app/models/slot.rb
class Slot < ActiveRecord::Base
#columns id | day | time | created_at | updated_at
#This will be populated with all the available "slots" -- EG day 0, time 1
enum day: [:monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
enum time: [:0900, :1000, :1100, :1130, :1200, :1300, :1330, :1400]
has_many :test_drives
has_many :clients, through: :test_drives
end
#app/models/test_drive.rb
class TestDrive < ActiveRecord::Base
#columns id | client_id | slot_id | created_at | updated_at
belongs_to :client
belongs_to :slot
end
#app/models/client.rb
class Client < ActiveRecord::Base
#columns id | title | name | company | street | house_nr | postal_code | city | email | phone | mobile | created_at | updated_at
has_many :test_drives
has_many :slots, through: :test_drive
def firstname
name.split(" ").first
end
end
您可以将验证添加到test\u drive
中,以确定是否占用了特定的插槽
您还可以将验证添加到插槽
模型中,以确定允许哪些日期
/时间
组合:
#app/models/slot.rb
class Slot < ActiveRecord::Base
...
validate :day_times
private
def day_times
permissible_times: {monday: [:0900, :1000], tuesday: [:1200]}
errors.add(:time, "Sorry, this time is unavailable on this day") unless permissible_times[day.to_sym].include? time
end
end
#app/models/slot.rb
类槽
你可以
目前存在的一个主要问题是,您已经用
client\uu
字段填充了TestDrives
表。虽然这会起作用,但这是一种失礼——它会很快变得笨重和负担过重
如上所述,有了关联,你会变得更好
谢谢您的回复。如果我理解正确,我将能够使用这种方法在星期六屏蔽例如10-11。然而,我需要的是更大致的:在特定日期2015年11月10日阻塞时间段x-y。如果日历的时间有限,比如说10天,我想你的方法是可行的,但事实并非如此。谢谢好的,谢谢你的回复-我猜想与你写的相反!
#app/models/slot.rb
class Slot < ActiveRecord::Base
...
validate :day_times
private
def day_times
permissible_times: {monday: [:0900, :1000], tuesday: [:1200]}
errors.add(:time, "Sorry, this time is unavailable on this day") unless permissible_times[day.to_sym].include? time
end
end