2012-11-29 64 views
0

我是新來的都Twilio和Ruby,我試圖找出如何「重定向」或者發送到另一個URL的請求。我不需要在這一步收集數據,只需評估一個傳遞的參數並將其發送到一個方向或另一個方向。任何幫助?重定向twilio紅寶石

post '/ors_verified/ors/:ors_number' do |ors_number| 
    number_correct = params['Digits'] 
    if number_correct == '1' 
      redirect "/how_many_irt/ors/#{ors_number}" 
    else 
      redirect '/how_many_ors' 
end 
end 

回答

2

所以,問題是,我需要把它包裝成一個twillio響應。

post '/ors_verified/ors/:ors_number' do |ors_number| 
    number_correct = params['Digits'] 
    Twilio::TwiML::Response.new do |r| 
    if number_correct == '1' 
     r.Redirect "/how_many_irt/ors/#{ors_number}" 
    else 
     r.Redirect '/how_many_ors' 
    end 
    end.text 
end 
+0

有一點要注意,如果你看到檢索錯誤是,以配合您的HTTP方法。如果您的目標方法定義爲GET,則默認值爲POST,並且不會完成。 – catalpa

2

你可以使用:的redirect_to代替redirect所以

post '/ors_verified/ors/:ors_number' do |ors_number| 
number_correct = params['Digits'] 
if number_correct == '1' 
     redirect_to "/how_many_irt/ors/#{ors_number}" 
else 
     redirect_to '/how_many_ors' 
end 
end 
+0

試過,但我得到: '' NoMethodError - 未定義的方法'redirect_to的」爲#<西納特拉::應用:0xb656609c>: '' – scottyaz

+0

我也看到有人使用redirect_to的:行動=> '/ URL'但那也行不通。 – scottyaz

0

既然你似乎可以用西納特拉重定向應該是這樣的:

post '/ors_verified/ors/:ors_number' do |ors_number| 
    number_correct = params['Digits'] 
    if number_correct == '1' 
      redirect to("/how_many_irt/ors/#{ors_number}") # <-- notice the #to 
    else 
      redirect to('/how_many_ors') # <-- notice the #to 
    end 
end 

#to基本上創建另一個對象從你的絃樂裏,sinatra可以採取行動。 你可以閱讀有關西納特拉重定向here