stevegraham/twilio-rb — Issue #20: Rails 3.2 compatibility
Author: rohit
Created: 2012-02-25 02:43:45+00:00
State: open

I tried using twilio-rb 2.1.3 with Rails 3.2. The Rails app wouldn't start. I would get the following error for even simple commands like:

```
rails g --help
/home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/twilio-rb-2.1.3/lib/railtie.rb:7:in `': uninitialized constant ActionView::Template::Handler (NameError)
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/twilio-rb-2.1.3/lib/railtie.rb:6:in `'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/twilio-rb-2.1.3/lib/railtie.rb:5:in `'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/twilio-rb-2.1.3/lib/railtie.rb:4:in `block in '
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/rohit/projects/mindpeck/config/environment.rb:5:in `'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/application.rb:103:in `require_environment!'
from /home/rohit/.rvm/gems/ruby-1.9.3-p0@mindpeck/gems/railties-3.2.1/lib/rails/commands.rb:25:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'

```

I don't think there is a Handler you can inherit from anymore. I can't confirm this but I was able to get Rails started with the following update to Twilio::Railtie:

```ruby
module Twilio
class Railtie < Rails::Railtie
initializer 'twilio.initialize' do |app|
module ActionView
module Template
module Handlers
class TwiML
class_attribute :default_format
self.default_format = 'text/xml'

def call(template)
<<-EOS
controller.content_type = 'text/xml'
Twilio::TwiML.build { |res| #{template.source} }
EOS
end
end
end
end
end

ActionController::Base.class_eval { before_filter Twilio::RequestFilter }

::ActionView::Template.register_template_handler(:voice, ActionView::Template::Handlers::TwiML)
::Mime::Type.register_alias 'text/xml', :voice
end
end
end
```

I'd be happy to write a patch for this but I don't know how this will play with <= Rails 3.1.x