To publish iCal through Rails, install iCalendar gem

gem install icalendar

then in Controller, code to export event ( export to *.ics file ) should look like,

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

One Response to “iCal ( iCalendar ) Publishing to *.ics file through RubyOnRails”


  1. [...] iCal (iCalendar) Publishing to *.ics file through RubyOnRails [...]


Leave a Reply