firstruby

Master ruby with us

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

Posted by firstruby on December 10, 2007

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

2 Responses to “iCal ( iCalendar ) Publishing to *.ics file through RubyOnRails”

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

  2. sundance vacations…

    [...]iCal ( iCalendar ) Publishing to *.ics file through RubyOnRails « firstruby[...]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.