Recurring Events in Calendar - Rails

后端 未结 4 1980
清酒与你
清酒与你 2021-01-29 22:06

I am searching for the best way to model recurring events. I am using fullcalendar to display events. But I guess recurring events are best handled on the rails backend.

4条回答
  •  半阙折子戏
    2021-01-29 22:52

    I m quite new to Rails, your solution sounds interesting. To create the schedule and associated occurences, do you use conditionnal callbacks in Event model?

    In my case, users would be able to create events, weekly recurring or not. So I was thinking about a recurring boolean field in event model. So I guess you would have a first callback to create the schedule:

    before_save :create_weekly_schedule, if: :recurring
    

    and basically a second one to create the occurences:

    after_save :create_occurences_if_recurring
    
    def create_occurences_if_recurring
      schedules.each do |sched|
        occurences.create(start_date: sched.start_time, end_date: sched.end_time)
      end
    end
    

    Does this sound logical with your solution? Thx

提交回复
热议问题