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

Advertisements

3 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[…]…

  3. “iCal ( iCalendar ) Publishing to *.ics file through RubyOnRails firstruby” was in fact a superb post.
    If solely there was way more personal blogs such as this one in the actual online world.
    Nonetheless, thanks a lot for your personal precious time,
    Lisa

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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: