1

I'm using labcoder's Twilio-Hackpack-for-Heroku-and-Sinatra then am following the Ruby Quickstart on Twilio's site. I've literally copied and pasted the code and it refuses to increment the counter.

The only difference between the quickstart code and my code is I use get_or_post:

get_or_post '/sms/?' do

Instead of their:

get '/sms-quickstart' do

When I use their get method with the /sms-quickstart, I get an ERROR (11200) HTTP Retrieval Failure. When I use get_or_post with /sms/?, it works, but my counter will not increment and I just keep getting the same "Hello, thanks for the new message." Here is the code from my app.rb

get_or_post '/sms/?' do
  session["counter"] ||= 0
  sms_count = session["counter"]
  if sms_count == 0
    message = "Hello, thanks for the new message."
  else
    message = "Hello, thanks for message number #{sms_count + 1}"
  end
  twiml = Twilio::TwiML::Response.new do |r|
    r.Sms message
  end
  session["counter"] += 1
  twiml.text
end
4

1 回答 1

3

Sinatra 默认不启用会话。需要在app.rb中添加以下内容:

enable :sessions

在此处查看文档

于 2013-05-22T15:17:08.187 回答