ruby-on-rails – ice_cube和recurring_select宝石和事件
发布时间:2020-12-16 19:18:45 所属栏目:百科 来源:网络整理
导读:我正在尝试利用ice_cube和recurring_select宝石的[超棒]功能来处理重复发生的事件.我的数据库中有一个schedule(text)列,事件模型中有以下内容: def schedule=(new_schedule) write_attribute(:schedule,RecurringSelect.dirty_hash_to_rule(new_schedule).t
我正在尝试利用ice_cube和recurring_select宝石的[超棒]功能来处理重复发生的事件.我的数据库中有一个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上有哪些功能可用)? 解决方法
在咨询了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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- reactjs – React-Router-Redux:在’react-router-redux’
- (H5)FormData+AJAX+SpringMVC跨域异步上传文件
- objective-c – NSMutableRLEArray objectAtIndex:effecti
- 输入银行卡号,每四位自动加一个空格
- 有没有办法在XCode 4中不使用断点来观察变量?
- 【Oracle】START WITH...CONNECT BY PRIOR...递归查询
- c# – OxyPlot获得点击的点
- JSONP跨域的原理解析
- ruby-on-rails – 在不同的控制器中渲染部分(不嵌套)
- xml文件的解析解析方式及Dom解析与Sax解析的区别