Ruby on rails Rails3XMLBuilder/TwilioAPI

Ruby on rails Rails3XMLBuilder/TwilioAPI,ruby-on-rails,ruby,xml,ruby-on-rails-3,twilio,Ruby On Rails,Ruby,Xml,Ruby On Rails 3,Twilio,此Twilio API示例代码在Rails 3中不起作用: #voice_controller.rb def reminder @postto = BASE_URL + '/directions' respond_to do |format| format.xml { @postto } end end #reminder.xml.builder xml.instruct! xml.Response do xml.Gather(:action

此Twilio API示例代码在Rails 3中不起作用:

#voice_controller.rb

  def reminder
    @postto = BASE_URL + '/directions'

    respond_to do |format|
      format.xml { @postto }
    end
  end

#reminder.xml.builder

xml.instruct!
xml.Response do
xml.Gather(:action => @postto, :numDigits => 1) do
    xml.Say "Hello this is a call from Twilio.  You have an appointment 
        tomorrow at 9 AM."
    xml.Say "Please press 1 to repeat this menu. Press 2 for directions.
        Or press 3 if you are done."
    end
end
有什么想法吗

Twilio似乎成功地拨打了电话(我可以看到带有我的电话号码、位置等的参数),但随后返回了这个模糊的响应代码:

Completed 406 Not Acceptable in 0ms

Twilio没有在中发送Accept HTTP头,这会导致Rails 3决定它无法使用适当的内容类型进行响应。不过,我认为以下几点可以帮助您解决这个问题:

# voice_controller.rb def reminder @postto = BASE_URL + '/directions' render :content_type => 'application/xml' end #语音控制器.rb def提醒 @postto=BASE_URL+'/directions' 呈现:内容类型=>'application/xml' 终止
Twilio没有在中发送Accept HTTP头,这会导致Rails 3决定它无法使用适当的内容类型进行响应。不过,我认为以下几点可以帮助您解决这个问题:

# voice_controller.rb def reminder @postto = BASE_URL + '/directions' render :content_type => 'application/xml' end #语音控制器.rb def提醒 @postto=BASE_URL+'/directions' 呈现:内容类型=>'application/xml' 终止
我是Twilio的雇员。自从发布这个原始问题以来,Rails已经有了很多变化,我想分享一下如何使用Rails 4、关注点和Twilio Ruby gem解决这个问题

在下面的代码示例中,我在
/controllers/voice_controller.rb
中定义了控制器,并包括一个称为Webhookable的问题。Webhookable关注点允许我们将与Twilio webhooks相关的逻辑(将HTTP响应头设置为text/xml、呈现TwiML、验证请求是否源自Twilio等)封装到单个模块中

require 'twilio-ruby'

class VoiceController < ApplicationController
  include Webhookable

  after_filter :set_header

  # controller code here

end
最后,下面是您的
提醒
操作可能的样子:使用Twilio gem生成TwiML并使用关注点将此对象呈现为文本:

  def reminder
    response = Twilio::TwiML::Response.new do |r|
      r.Gather :action => BASE_URL + '/directions', :numDigits => 1 do |g|
        g.Say 'Hello this is a call from Twilio.  You have an appointment 
    tomorrow at 9 AM.'
        g.Say 'Please press 1 to repeat this menu. Press 2 for directions.
    Or press 3 if you are done.'
      end
    end

    render_twiml response
  end

我是Twilio的雇员。自从发布这个原始问题以来,Rails已经有了很多变化,我想分享一下如何使用Rails 4、关注点和Twilio Ruby gem解决这个问题

在下面的代码示例中,我在
/controllers/voice_controller.rb
中定义了控制器,并包括一个称为Webhookable的问题。Webhookable关注点允许我们将与Twilio webhooks相关的逻辑(将HTTP响应头设置为text/xml、呈现TwiML、验证请求是否源自Twilio等)封装到单个模块中

require 'twilio-ruby'

class VoiceController < ApplicationController
  include Webhookable

  after_filter :set_header

  # controller code here

end
最后,下面是您的
提醒
操作可能的样子:使用Twilio gem生成TwiML并使用关注点将此对象呈现为文本:

  def reminder
    response = Twilio::TwiML::Response.new do |r|
      r.Gather :action => BASE_URL + '/directions', :numDigits => 1 do |g|
        g.Say 'Hello this is a call from Twilio.  You have an appointment 
    tomorrow at 9 AM.'
        g.Say 'Please press 1 to repeat this menu. Press 2 for directions.
    Or press 3 if you are done.'
      end
    end

    render_twiml response
  end

XML builder文件放在哪里???XML builder文件放在哪里???