宝石ice_cube为reccurence事件 [英] gem ice_cube for reccurence events

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

问题描述

我有简单的事件模型(标题,日期,用户)
我按月创建了活动日历(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...)

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

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