Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Publishing ICalendar with Ruby on Rails

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 2.95k
    Comment on it

    If your application has certain events(For example meeting etc), then you may need to integrate calendar application.
    Icalendar is a standard for calendar data exchange.
    Icalendar allows us to generate .ics files so that users can add events to their calendars.

    First of all install the gem

    gem install icalendar


    And run bundle install
    After this add require 'icalendar' to your config/environment.rb

    Suppose we have a MeetingEvent model:

    class MeetingEvent < ActiveRecord::Base
    # Table name: meeings_events
    #  id           :integer(11)     not null, primary key
    #  title        :string(255)
    #  start_date    :datetime
    #  end_date     :datetime
    #  summary      :text
    #  created_at   :datetime
    #  updated_at   :datetime


    The next part is added "to_icalender" action of the MeetingController to accept .ics format:

    def to_icalender
            @event = MeetingEvent.find(params[:id])
            respond_to do |format|
              format.ics do
                cal =           
                    event =
                    event.dtstart = @event.starts_at
                    event.dtend = @event.ends_at  
                    event.summary = @event.title
                    event.uid = event.url = "#{event_url}"
                    render :text =>  cal.to_ical

    Add a link to your view:

    <%= link_to @event.title, :controller => 'meeting', :action => :to_icalender, :format => :ics %>

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: