2011-12-26 29 views
0

如果用戶回覆接收到的短信,我有一個短信網關會將我的獲取請求推給我。Rails 3.1具有固定結構化參數的路由

# gateway pushes following fixed style get-params 
# to my server/reply_from_gateway-action: ?id=123456&answer=Test 

# => http://myserver.aaa/reply_from_gateway?id=123456&answer=Test 

現在我想添加下列路線,因爲短信網關有一個定義的GET參數結構:

get "deactivate_via_sms?id=:id&answer=:answer" => "reminders#deactivate_via_sms" 
     :as => "deactivate_via_sms" 

但是,這並不工作,你能幫幫我嗎?

回答

0

您可以通過用手拉CGI風格的參數超出params在你的控制器,你不需要(或希望)他們在路線:

get "deactivate_via_sms" => "reminders#deactivate_via_sms", :as => "deactivate_via_sms" 

,然後在RemindersController#deactivate_via_sms

def deactivate_via_sms 
    id  = params[:id] 
    answer = params[:answer] 
    #... 
end 
+0

哦..是的^^ lolol THX – Lichtamberg 2011-12-26 23:59:05

0

您可以通過用手拉CGI風格參數OUT參數,在你的控制器,你不需要(或希望)他們在路線

但在這種情況下,你不能使用助手如

deactivate_via_sms_path(id,answer) 

,或者您可以使用此代碼創建助手

get "deactivate_via_sms?id=:id&answer=:answer" => "reminders#deactivate_via_sms" 
    :as => "deactivate_via_sms" 

但你的路由將失敗

我解決了這個通過更改「?」來解決問題爲 「/」 的路線

get "deactivate_via_sms/id=:id&answer=:answer" => "reminders#deactivate_via_sms" 
    :as => "deactivate_via_sms" 

路由工程和輔助方法,也能正常工作