鉴于我具有以下事件的以下数据,作为ruby on rails中的哈希值:
event = {
start_at: Time.now(),
end_at: Time.now() + 3600,
summary: 'My meeting',
description: 'A zoom meeting about food',
event_url: 'https://food.example.com',
formatted_address: ''
}
如何将动态创建的ical / ics文件传送给用户该信息?
icalendar宝石效果很好。 https://github.com/icalendar/icalendar
我使用它来生成Outlook和ical版本。效果很好。
cal = Icalendar::Calendar.new
filename = "Foo at #{foo.name}"
if params[:format] == 'vcs'
cal.prodid = '-//Microsoft Corporation//Outlook MIMEDIR//EN'
cal.version = '1.0'
filename += '.vcs'
else # ical
cal.prodid = '-//Acme Widgets, Inc.//NONSGML ExportToCalendar//EN'
cal.version = '2.0'
filename += '.ics'
end
cal.event do |e|
e.dtstart = Icalendar::Values::DateTime.new(foo.start_at, tzid: foo.time_zone)
e.dtend = Icalendar::Values::DateTime.new(foo.end_at, tzid: foo.course.time_zone)
e.summary = foo.summary
e.description = foo.description
e.url = event_url(foo)
e.location = foo.formatted_address
end
send_data cal.to_ical, type: 'text/calendar', disposition: 'attachment', filename: filename