开发者

Rails 3: Automatically create entries in table using preset values

Currently, I'm building a scheduling system for my workpla开发者_如何学Pythonce. 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.


You should use a factory to initialize your objects. Have a look at https://github.com/thoughtbot/factory_girl

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜