用于重复事件的 gem ice_cube [英] gem ice_cube for reccurence events

查看:7
本文介绍了用于重复事件的 gem ice_cube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的事件模型(标题、日期、用户)我按月创建了事件日历(gem 'watu_table_builder').我需要创建重复事件的功能.我发现我可以使用 gem ice_cube .但我不清楚.

I have simple Event model (title, date, user) And I created Events Calendar by months (gem 'watu_table_builder'). I need the feature to create repeating events. I figured out that I may use gem ice_cube for it. But it is not clear for me.

我添加到模型中:

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) 如何将重复规则与事件数组结合起来?

1) How I may combine repeat rules with Events array?

2) 据我了解,我可以将有关 yaml 中重复的信息保存到数据库中yaml = schedule.to_yaml

2) As I understand, I may save to db information about repeats in yaml yaml = schedule.to_yaml

但我不清楚如何为重复创建下拉列表(无、每天、每月、每年)并将其与调度规则链接.我应该在哪里以及如何实现它(将用户选择转换为正确的时间)

But it is not clear for me how it is good way to create drop-down for repeats (none, each day, each month, each year) and link it with shedule rules. Where and how I should realize it (convert user choise to right shedule)

推荐答案

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

You won't be able to query the database for the Event's serialized (yaml) schedule to filter occurrences by month, if that's what you're trying to do. If you need to do that, then you'll have to store the schedule.occurrences as rows in a separate table join: that's what I do in our app.

稍后我可能会在此答案中添加更多详细信息,同时查看我的 schedule_attributes gem如果它可以帮助您根据用户输入构建用于构建时间表的选择器(我仍然需要更新文档并发布它......)

I might have more details to add to this answer later, meanwhile have a look at my schedule_attributes gem if it helps you build the selectors for building schedules from user input (I still need to update docs and release it...)

这篇关于用于重复事件的 gem ice_cube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆