我有简单的事件模型(标题、日期、用户)
我按月创建了事件日历(gem 'watu_table_builder')。我需要创建重复事件的功能。我发现我可以使用 gemice_cube 来实现它。但我不清楚。
我添加到模型:
class Event < ActiveRecord::Base
#require 'ice_cube'
include IceCube
belongs_to :user
validates :title, :presence => 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)如何将重复规则与事件数组结合起来?
2)据我了解,我可以将有关yaml中重复的信息保存到数据库中
yaml = 时间表.to_yaml
但我不清楚创建重复下拉列表(无、每天、每月、每年)并将其与日程规则链接起来是如何的好方法。我应该在哪里以及如何实现它(将用户选择转换为正确的时间表)
如果您想要执行此操作,您将无法在数据库中查询事件的序列化 (yaml) 计划来按月筛选事件。如果您需要这样做,那么您必须存储schedule.occurrences
作为单独表中的行连接:这就是我在我们的应用程序中所做的。
稍后我可能会有更多详细信息添加到这个答案中,同时看看我的时间表属性gem 如果它可以帮助您构建用于根据用户输入构建时间表的选择器(我仍然需要更新文档并发布它......)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)