0

我正在使用

导轨 6.0.3

宝石'simple_calendar'

并使用

宝石“冰立方”

会议控制器中,我调用calender_meetings会议需要重复的次数作为参数

def index
  @meetings = current_user.meetings
  @calender_meetings = @meetings.flat_map{ |m| m.calender_meetings(m.repeat) }
end

meeting.rb文件中,我使用 ice::cube gem 来处理重复事件,使用 (repeat) 计算有多少实例

  def schedule
    date = start_time.to_date
    schedule = IceCube::Schedule.new(now = date)
    case occurrence
      when 'once'
      when 'daily'
        schedule.add_recurrence_rule IceCube::Rule.daily
      when 'weekly'
        schedule.add_recurrence_rule IceCube::Rule.weekly
      when 'monthly'
        schedule.add_recurrence_rule IceCube::Rule.monthly(1)
      when 'six_monthly'
        schedule.add_recurrence_rule IceCube::Rule.monthly(6)
      when 'yearly'
        schedule.add_recurrence_rule IceCube::Rule.yearly(1)
    end
    schedule
  end

  def calender_meetings(repeat)
    if occurrence == "once"
      Meeting.new(id: id, user_id: user_id, name: name, start_time: start_time, end_time: end_time, complete: complete, description: description, occurrence: "once", priority: priority )
    else
      schedule.first(repeat).map do |date|
        Meeting.new(id: id, user_id: user_id, name: name, start_time: date, end_time: date, complete: complete, description: description, occurrence: "once", priority: priority, repeat: 0 )
      end
    end
  end

calendar_meetings方法迭代中schedule.first(repeat).map,我需要为每个实例创建一个唯一 ID。我有一个完整的布尔值,只需要删除一个会议 - 即使它是重复的并且无法弄清楚如何

4

0 回答 0