从rails模型动态创建一个ics / ics文件(dynamically create an ical / ics file from a rails model)

编程入门 行业动态 更新时间:2024-10-26 10:30:40
从rails模型动态创建一个ics / ics文件(dynamically create an ical / ics file from a rails model)

鉴于我需要将所有信息存储在rails应用程序中的:event模型中。 如何向视图添加按钮,单击该按钮时会提供动态创建的ics / ics文件?

我环顾了几天,我发现的所有信息似乎已经过时或假设我已经知道如何做大块的解决方案。

Given that I have all the info I need stored in an :event model in a rails app. How do I add a button to a view which when clicked delivers a dynamically created an ical/ics file?

I've looked around for a few days and all the info I'm finding seems out of date or assumes that I already know how to do big chunks of the solution.

最满意答案

icalendar gem运作良好。 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

The icalendar gem works well. https://github.com/icalendar/icalendar

I use this to generate outlook and ical versions. Works great.

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

更多推荐

本文发布于:2023-08-07 20:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   模型   文件   动态   ics

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!