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.

Spread the word: Technorati related  |  Technorati related  |  del.icio.us bookmark it!  |  submit Rails iCalendar improvement digg.com digg it!  |  reddit reddit!

3 Responses to “Rails iCalendar improvement”

  1. Daniel Higginbotham says:

    I believe renderwithoutlayout has been deprecated and render(:layout => false, :text => whatever) is preferred, but I might be totally wrong about that.

  2. Miles says:

    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.

  3. Justin Halsall says:

    you could also do this:
    render(:inline => whatever)
    instead of render(:layout => false, :text => whatever) or renderwithoutlayout

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>