Reputation: 313
I have a paid account with Twilio. In my rails app I have a very simple setup to answer an incoming phone call in rails with twilio. In routes.rb
, I have
post 'communications/answer_phone' => 'communications#answer_phone'
In communications_controller.rb
, I have
class CommunicationsController < ApplicationController
skip_before_action :verify_authenticity_token
def answer_phone
logger.debug '******** answered'
response = Twilio::TwiML::Response.new do |r|
r.Say "Yay! You’re on Rails!", voice: "alice"
end
render :xml => response.to_xml
end
end
If I try to call my Twilio number, ngrok says 500 Internal Server Error
, so I know the request is getting to ngrok. If I look at my rails log file, I see
Started POST "/communications/answer_phone" for xxx.xxx.xxx.xxx at 2017-02-02 21:47:06 +1100
so, the request is making it to my application. I don't get ******** answered
in my log file from logger.debug
. The request never makes it to my answer_phone
action. Any ideas what could be wrong?
UPDATE
I've done rake routes
and that gives me
communications_receive_sms POST /communications/answer_phone(.:format) communications#answer_phone
That looks correct. If I deliberately spell the route incorrectly in routes.rb
, I get this error
ActionController::RoutingError (No route matches [POST] "/communications/answer_phone"):
So I know the request is getting to my rails application and I know it is finding the route. What could cause rails to find the appropriate route but fail the call the associated action.
Upvotes: 0
Views: 202
Reputation: 313
I've found a bug in rails 4.18. There is an example on the internet that makes it happen. See the link below
https://www.twilio.com/blog/2016/05/calling-rails-5-getting-started-with-twilio-on-rails.html
The example is for rails 5, so the bug must be fixed now. The following code line causes the error.
r.Say "Yay! You’re on Rails!", voice: "alice"
The apostrophe in "Yay! You’re on Rails!"
is not the standard one on my computer keyboard. The normal apostrophe is hex character 0x27, the one in the word You’re is hex character 0x92. This causes a parsing error in rails. Even if I route to a different action in that controller, the error still occurs.
I hope this helps someone in the future.
EDIT
If you change the apostrophe, you'll have to restart your rails server to correct the problem
Upvotes: 1