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.
when to remind
can have different types of values?
Some things I thought of:
I was thinking of creating a column for each type (remind_in_days, remind_in_weeks, remind_at)
-->But this feels a bit kludgy.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 likeif remind_type==x then x
??
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
.
精彩评论