Sending an iCal as attachment in rails 3

7 Mar 2013, by Michael Cindrić

Sending iCal files in rails can sometimes be a pain. The trick is to set the mime type for the attachment and all should be fine.

In the example below the "calendar_entry" variable is a reference to the class that is used to build up the iCal. Now you can use something like icalendar which is what l have used as well.

All you need to do is set the mime type as below and set the content as below as well.

attachments["meeting.ics"] = {:mime_type => 'text/calendar',
                              :content => calendar_entry.to_ical}

The to_ical method will return the ical object. I dont recommend reading in a file like below as that tends to write the ical out and some mail clients dont like it

:content =>"public/#{}.ics")} 

Cookies help us deliver our services. By using our services, you agree to our use of cookies.