3

アクティブリソースを通じて新しい顧客を作りたいです。authentication_key がなければ大したことではありません。私はdevise認証とcancanを使用しています。

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

上記のコードを使用して新しい顧客を作成すると、Web サーバーへの xml 要求は

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

顧客モデルによってラップされた問題 ID auth_token。そのため、認証に失敗し、401 応答が返されました。

この形式のリクエストを作成するソリューションはありますか?

パラメータ: {"customer"=>{"first_name"=>'sampath', "last_name"=>"munasinghe"}, "auth_token"=>"af34afafasfasfasaf"}}

注: auth_token は顧客ブロックの外にあります。

ありがとう

4

1 に答える 1

2

json の場合、これを行う最も簡単な方法は、Customer.include_root_in_json を false に設定することです。

次に、次のコードを使用します。

customer = Customer.create(:customer => [:fname=>'sampath' , :last_name=>'munasinghe'],:auth_token=>'af34afafasfasfasaf')
于 2011-03-31T14:36:03.990 に答える