Rails抛出了丢失的模板错误而没有改变任何东西

时间:2014-06-13 17:31:15

标签: ruby-on-rails twilio

我的生产轨道应用程序已经使用了几个月,没有任何问题。我最近没有做过任何重大改动(而且几天都没有),然后今天早上,airbrake为我所说的特定回调投掷了一堆错误:

ActionView::MissingTemplate (Missing template calls/receive_call, application/receive_call

我最近没有更改视图或路线中的任何内容,可能是什么原因造成的?这是我的接听电话方法:

  def receive_call
    to_number   = params[:To]   == '+1' ? params[:Called].slice!(2..12) : params[:To].slice!(2..12)
    from_number = params[:From] == '+1' ? params[:Caller].slice!(2..12) : params[:From].slice!(2..12)
    company = PhoneNumber.find_by(number: to_number).company
    customer = company.customers.find_or_create_by(customer_phone_number: from_number)
    if company && customer
      call = company.calls.create(
        from:         from_number,
        to:           to_number,
        customer_id:  customer.id,
        call_status:  params[:CallStatus],
        call_sid:     params[:CallSid],
        forwarded_to: company.forwarding_number
      )
      forwarding_number = company.twilio_formatted_forwarding_number
      if forwarding_number
        render 'twilio/call_response.xml.haml', locals: { forwarding_number: forwarding_number }, content_type: 'text/xml'
      end
    else
      puts 'ERROR (receive_call): company or customer couldn\'t be loaded'
    end
  end

我以前从来没有需要这个回调的视图(来自twilio)......但是现在它说我需要一个。发生了什么事?

1 个答案:

答案 0 :(得分:0)

我猜,这是你第一次出错 如果发生错误,则使用puts输出错误 在操作结束时,Rails尝试渲染标准视图,因为还没有渲染。

您可以将纯文本呈现为

      if forwarding_number
        render 'twilio/call_response.xml.haml', locals: { forwarding_number: forwarding_number }, content_type: 'text/xml'
      else
        render text: 'ERROR (receive_call): no forwarding number.'
      end
    else
      render text: 'ERROR (receive_call): company or customer couldn\'t be loaded'
    end

或在puts之后返回:

puts 'ERROR (receive_call): company or customer couldn\'t be loaded'
return

原因是,无论是否有错误,都应该呈现相同类型的响应(XML),所以做得更好

render xml: {error: 'ERROR (receive_call): company or customer couldn\'t be loaded'}, status: 404