twilio_mime makes returning TwiML in Rails even easier

June 08, 2010
Written by
John Sheehan
Contributor
Opinions expressed by Twilio contributors are their own

Twilio Bug Logo

Mime
Dale Cook is a Ruby programmer that was looking for an easier way to send back TwiML is his Rails applications.
Like any good programmer seeking a better way to do things, Dale built a Rails plugin to take advantage of the framework’s ‘respond_to’ feature.
Using twilio_mime you can respond to Twilio requests using TwiML in the same way you’d handle other mime types.

An example of how this works is available in the project’s readme file on GitHub.
We start with the ‘show’ action of our sample ‘Posts’ controller:

def show
@posts = Post.find :all
respond_to do |format|
format.html
format.twiml
format.xml { render :xml => @posts.to_xml }
end
end

Then, create a view to generate the TwiML response called ‘show.twiml.erb’:

<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<% @posts.each do |post| %>
<Say><%= post.title %></Say>
<% end %>
</Response>

To keep up with the project and read more of Dale’s musings on Ruby, check out his Ruby blog
called Little Shards of Ruby.
twilio_mime has an MIT license and can be found on GitHub. Go check it out!

Photo credit: Carosaurus on Flickr