Check out the Google Calendar gem for rails. It lets you display a user's Google Calendar in your rails app and they have sample snippets showing how to export events to Google Calendar:
require 'googlecalendar'
g = GData.new
g.login('REPLACE_WITH_YOUR_MAIL@gmail.com', 'REPLACE_WITH_YOUR_PASSWORD')
event = { :title=>'title',
:content=>'content',
:author=>'pub.cog',
:email=>'pub.cog@gmail.com',
:where=>'Toulouse,France',
:startTime=>'2007-06-06T15:00:00.000Z',
:endTime=>'2007-06-06T17:00:00.000Z'}
g.new_event(event)
For iCal, use the iCalendar gem and then you can export events as follows:
require ‘icalendar’
class EventController < ApplicationController
def export_events
@event = Event.find(params[:id])
@calendar = Icalendar::Calendar.new
event = Icalendar::Event.new
event.start = @event.dt_time.strftime(”%Y%m%dT%H%M%S”)
event.end = @event.dt_time.strftime(”%Y%m%dT%H%M%S”)
event.summary = @event.summary
event.description = @event.description
event.location = @event.location
@calendar.add event
@calendar.publish
headers['Content-Type'] = “text/calendar; charset=UTF-8″
render_without_layout :text => @calendar.to_ical
end
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…