2011-03-21 47 views
3

我想通過主動資源創建一個新客戶。沒有authentication_key它沒有什麼大不了的。我正在使用設計認證和cancan。主動資源的自定義參數

customer = Customer.create(:fname=>'sampath , :last_name=>'munasinghe' ,:auth_token=>'af34afafasfasfasaf') 

如果我用上面的代碼來創建一個新的客戶,XML請求的Web服務器是

Parameters: {"customer"=>{"first_name"=>'sampath', "last_name"=>"munasinghe", "auth_token"=>"af34afafasfasfasaf"}} 

問題ID的auth_token由客戶模型包裹。所以,身份驗證失敗並返回401響應。

有沒有解決方案來創建這種格式的請求?

參數:{ 「客戶」=> { 「FIRST_NAME」=> '薩姆帕斯', 「姓氏」=> 「穆納辛格」}, 「AUTH_TOKEN」=> 「af34afafasfasfasaf」}}

注意: auth_token位於客戶區塊之外。

感謝

+0

http://stackoverflow.com/questions/2918419/add-api-key-to-every-request-in-activeresource ?? – Fivell 2011-03-31 14:30:11

回答

2

JSON的做到這一點的最簡單的方法是設置Customer.include_root_in_json爲false。

然後使用此代碼:

customer = Customer.create(:customer => [:fname=>'sampath' , :last_name=>'munasinghe'],:auth_token=>'af34afafasfasfasaf')