Skip to content

Instantly share code, notes, and snippets.

@tabishiqbal
Forked from excid3/controller.rb
Created September 23, 2019 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabishiqbal/edcbd0dd5f8c22a366f5e701a6d037c5 to your computer and use it in GitHub Desktop.
Save tabishiqbal/edcbd0dd5f8c22a366f5e701a6d037c5 to your computer and use it in GitHub Desktop.
def create
@room = Room.find(params[:room_id])
@event = @room.events.create(event_params)
@event.create_recurring_events
end
class Event
attribute :recurring, :boolean
def create_recurring_events
return unless recurring?
schedule.occurrences(end_time).each do |time|
# use the current event's attributes to populate the new one,
# but override the start time with the one from the schedule
room.events.create(attributes.merge(start_time: time))
end
end
def schedule
# your ice_cube schedule
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment