Topic: icalendar gem => proper .ics file

Hello Forum

I am experimenting with the icalendar gem and have an event table
that i want to use to produce icalendar output according to the suggestions on:

http://blog.milesbarr.com/2006/06/icalendar-and-rails/

I am able to render icalendar content into the browser.
To verify that the icalendar format is correct i use mozilla sunbird to subscribe to the calendars but when using extensive text descriptions sunbird compains about the calendar output not being utf-8 compliant and does not load the calendar.

Also I do not know how to get a the response as a .ics file instead of a html header. To get the utf-8 comopliance What should I manipluate and what should I enter:
a) apache conf files
b) apache .htaccess files
c) some rail file in the app/view directory

I would prefer to steer away from a) as I am unsure whether I can manipulate this area in a hosted production environment.

Thanx for Suggestions R

Re: icalendar gem => proper .ics file

All you need to do is define the header in the action that displays your ical file.  Like so (this code totally doesn't work, it's just an example):

def ical
  ical = Ical.find(params[:id])
  headers['Content-Type'] = "application/ical_something_or_other"
  render_without_layout :text => ical.to_html
end

Re: icalendar gem => proper .ics file

Thanx for the input: I modified my code and here is the code from my ical controller:
I am stilly struggeling with the "utf-8" message from fribird (which I am using  initially to verify if I hav a proper ical format).
Any clues how to get the line to work:
"event.description = ev.description" (Plain text field with a lot of german text)   

code:
1. def evcal
2.    @cal = Icalendar::Calendar.new
3.    Event.find_all.each do |ev|
4.      event = Icalendar::Event.new
5.     #TODO: Handle Timezones   
6.      event.start = ev.date.strftime("%Y%m%dT%H%M%S")
7.      event.end =  ev.date.since(3600).strftime("%Y%m%dT%H%M%S")
8.      event.summary = ev.name
9.      event.description = ev.description)
10.      @cal.add event
11.    end
12.    headers['Content-Type'] = "text/calendar; charset=UTF-8"
13.     render_without_layout :text => @cal.to_ical
14. end

Thanx Roland

Re: icalendar gem => proper .ics file

had this same problem, the solution you showed was my first attempt.

this was broken in IE6 => outlook.

then I found the fix in the rails source: application_controller/streaming.rb:

@headers['Cache-Control'] = 'private' if @headers['Cache-Control'] == 'no-cache'

then decided just to use this way of sending the ics file altogether
instead of messing with headers and rendering with no layout, simply:

send_data(cal.to_ical, :type => 'text/calendar', :disposition => 'inline; filename=event23.vcs', :filename=>'event23.vcs')

heres a working example using the icalendar gem:

cal = Icalendar::Calendar.new
cal.custom_property("METHOD","PUBLISH")
event = Icalendar::Event.new 
event.dtstart = @calendar.event_start_date
event.dtend = @calendar.event_end_date
event.summary = 'Meet with client CLIENT NAME'       
event.description = 'Meet with client' + @calendar.event_summary
event.klass = "PUBLIC"       
#event.transp = "TRANSPARENT"
event.location = "Manhattan Office"   
#event.priority = 5       
cal.add_event(event)
send_data(cal.to_ical, :type => 'text/calendar', :disposition => 'inline; filename=event23.vcs', :filename=>'event23.vcs')

Enjoy!

Re: icalendar gem => proper .ics file

really thanks guys,,.
its very useful.
using ur idea, i have implemented it ..
here is that post..

http://www.srijjhero.blogspot.com