Rails 3:使用预设值自动在表中创建条目
目前,我正在为我的工作场所构建一个调度系统。这是一个人流量很大的大学导游办公室,根据当天的活动时间表和所有可用导游的轮班,系统会将旅行分配给可用的导游。
但是,当要求用户构建当天的活动时间表(或旅行列表)时,我更希望自动生成一个时间表,然后他们可以进行操作。只有两种不同类型的日程安排,根据一周中的某一天交替使用,这种领先优势将节省大量时间。
我的问题:我应该把这些“种子”数据放在哪里?我是否应该创建一个 YAML,然后让一个方法读取它以使用适当的默认值填充给定的日期?
作为参考,我的模型目前的结构如下:
guide has_many :tours, :shifts
shifts belongs_to :guide
tour belongs_to :guide
我考虑过“日”模型,但由于每次都是日期时间,我觉得这太多余了,无法持久保存到数据库中。
谢谢!欢迎所有建议。我只是想掌握正确的“Rails Way”来处理这个问题。
Currently, I'm building a scheduling system for my workplace. It's a highly-trafficked university tour guide office, and given a schedule of the day's events and the shifts of all available tour guides, the system will assign tours to available tour guides.
But, when asking a user to build the event schedule (or list of tours) for the day, I'd prefer to have a schedule auto-generated that they can then manipulate. There are only two different types of schedules that alternate depending on the day of the week, and this head start will save a lot of time.
My question: Where do I put this 'seed' data? Should I create a YAML and then have a method read it to populate a given day with appropriate defaults?
For reference, my models are currently structured like so:
guide has_many :tours, :shifts
shifts belongs_to :guide
tour belongs_to :guide
I've considered a 'day' model but as every time is a datetime, I felt like this was too redundant to persist to the database.
Thanks! All suggestions welcome. I'm just trying to get a good grip on the proper "Rails Way" to handle this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用工厂来初始化您的对象。看看 https://github.com/thoughtbot/factory_girl
You should use a factory to initialize your objects. Have a look at https://github.com/thoughtbot/factory_girl