Rails iCalendar improvement
I came across this thread that simplifies the ical controller from my previous example. It correctly sets the content type header and removes the need for a template. The new version is:
class IcalController < ApplicationController
caches_page :competitions
def competitions headers[’Content-Type’] = “text/calendar”
cal = Icalendar::Calendar.new
Competition.find_all.each do |comp|
event = Icalendar::Event.new
event.start = comp.date
event.end = comp.date
event.summary = comp.name
cal.add event
end
render_without_layout :text => cal.to_ical
end
I hadn’t used the render_without_layout command before, but it’s very handy for situations like this.

November 16th, 2006 at 4:32 am
I believe renderwithoutlayout has been deprecated and render(:layout => false, :text => whatever) is preferred, but I might be totally wrong about that.
November 16th, 2006 at 9:51 am
Thanks for the heads up Daniel. I’ve been living in Rails 1.0 land for a while. I plan to upgrade my apps to the latest sometime this winter.
April 6th, 2008 at 10:30 am
you could also do this:
render(:inline => whatever)instead of
render(:layout => false, :text => whatever)orrenderwithoutlayout