ice_cube和recurring_selectgem和事件

我正在尝试利用ice_cube和recurring_selectgem的[超棒]function来处理重复发生的事件。 我的数据库中有一个schedule (text)列,事件模型中有以下内容:

  def schedule=(new_schedule) write_attribute(:schedule, RecurringSelect.dirty_hash_to_rule(new_schedule).to_yaml) end def converted_schedule Schedule.from_yaml(self.schedule, :start_date_override => self.start_date) end 

查看psql中的schedule列,它似乎正确地存储了日程表。

这是我的表格:

 .control-group = f.label 'Date', :class => 'control-label' .controls = f.text_field :start_date, :class => 'datepicker' .control-group = f.label 'Recurring?', :class => 'control-label' .controls = f.select_recurring :schedule, :allow_blank => true 

但是,当我尝试输出converted_schedule ,它只显示开始日期,不会显示任何其他日期。 我有一些怀疑,我没有成功修改…也许YAML没有正确转换为converted_schedule方法? 也许我需要一个结束日期(我不知道recurring_select上有哪些function可用)?

在咨询了John Crepezzi(ice_cube gem的作者 – 感谢John!)之后,我发现我存储了重复的规则而不是计划本身。 以下代码修复了此问题:

 serialize :schedule, Hash def schedule=(new_schedule) write_attribute(:schedule, RecurringSelect.dirty_hash_to_rule(new_schedule).to_hash) end def converted_schedule the_schedule = Schedule.new(self.start_date) the_schedule.add_recurrence_rule(RecurringSelect.dirty_hash_to_rule(self.schedule)) the_schedule end 

注意:我还切换到将该列存储为哈希而不是之前发布的YAML。