如何使用rails和ri_cal创建.ics文件?

时间:2010-10-07 16:16:11

标签: ruby-on-rails icalendar

我正在使用rails 3和ri_cal gem。我无法生成有效的.ics文件。它会生成,但AppleCalendar或GoogleCalendar表示它是空的。我做错了什么? 感谢提前感谢:)

我的控制器

class WebsitesController < ApplicationController
  def index

    respond_to do |format|

      format.ics 

    end
  end
end

和index.ics.builer

RiCal.Calendar do
    event do
      description "MA-6 First US Manned Spaceflight"
      dtstart     DateTime.parse("2/20/1962 14:47:39")
      dtend       DateTime.parse("2/20/1962 19:43:02")
      location    "Cape Canaveral"
      add_attendee "john.glenn@nasa.gov"
      alarm do
        description "Segment 51"
      end
    end
  end

1 个答案:

答案 0 :(得分:3)

我能够成功获得由

创建的ICS
def index
 cal =RiCal.Calendar do
   event do
     description "MA-6 First US Manned Spaceflight"
     dtstart DateTime.parse("1962-02-20")
     dtend DateTime.parse("1962-02-20")
     location "Cape Canaveral"
     add_attendee "john.glenn@nasa.gov"
     alarm do
       description "Segment 51"
     end
   end
 end
 respond_to do |format|
  format.ics { send_data(cal.export, :filename=>"mycal.ics", :disposition=>"inline; filename=mycal.ics", :type=>"text/calendar")}
 end
end

不需要离散构建器