用于复原事件的gem ice_cube

我有简单的事件模型(标题,日期,用户)我创建了几个月的事件日历(gem’watu_table_builder’)。 我需要该function来创建重复事件。 我发现我可能会使用gem ice_cube。 但我不清楚。

我添加到模型:

class Event  true, :length => { :minimum => 5 } validates :shedule, :presence => true def self.events_and_repeats(date) @events = Event.where(shedule:date.beginning_of_month..date.end_of_month) # Here I need to figure out what is events repeats at this month (from date param) # how I may combine it with Events array @events_repeats = @events # + repeats return @events_repeats end 

1)如何将重复规则与Events数组相结合?

2)据我所知,我可以在yaml yaml = schedule.to_yaml中保存有关重复的db信息

但我不清楚如何为重复创建下拉列表(没有,每天,每个月,每年),并将其与shedule规则联系起来。 我应该在哪里以及如何实现它(将用户选择转换为正确的)

如果您正在尝试执行此操作,则无法在数据库中查询事件的序列化(yaml)计划以按月过滤事件。 如果你需要这样做,那么你必须将schedule.occurrences存储为一个单独的表连接中的行:这就是我在我们的应用程序中所做的。

我可能稍后会有更多细节添加到此答案中,同时查看我的schedule_attributes gem,如果它可以帮助您构建用于从用户输入构建计划的选择器(我仍然需要更新文档并释放它…)