开发者

How to model a schedule in Rails?

Using Ruby on Rails 2.3.8, I'm wondering how to represent a schedule for model that handles "reminders".

Examples of reminder:
"Must do ABC", Remind me in 3 days
"Must do DEF", Remind me in 5 weeks
"Must do XYZ", Remind me on 2nd Oct 2010 at 5 pm

So, the Must do... goes into a description column.

But how to deal with the fact that when to remind can have different types of values?

Some things I thought of:

  1. I was thinking of creating a column for each type (remind_in_days, remind_in_weeks, remind_at)

    -->But this feels a bit kludgy.

  2. Have a field called remind_type which will be used to determine the type of value stored in a field called remind_type_value

    -->If I use thi开发者_如何学Cs approach, is there a way that I can simply say in Rails code something like Reminder.RemindValue without having to use code like if remind_type==x then x?

  3. ?

Any ideas of how I should proceed (in a manner that is possibly elegant)?


Why not just hard code times from now when when saving? "Remind me in two weeks" when saving could just do something like, reminder.remind_at = 2.weeks.from_now.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜