2011-12-06 2 views
0

riakデータベースで顧客を更新しようとしていますが、次のエラーメッセージが表示されます: このエラーの原因とそのエラーメッセージ。は、顧客がエルランに置かれた場合に更新することはできません

そして、私が使用してモジュールがある:

allowed_methods(Request, State) -> 
    {['PUT'], Request, State}. 

content_types_accepted(Request, State) -> 
    {[{"application/json",to_json}], Request, State}. 

エラー

webmachine error: path="/customer/cus/update" {error, {error,undef, [{customer_update,to_json, [{wm_reqdata,'PUT',http, {1,1}, "127.0.0.1", {wm_reqstate,#Port<0.6513>, {dict,4,16,16,8,80,48, {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}, {{[],[],[], [[mediaparams,{"charset","UTF-8"}]], [], [[resource_module|customer_update], ['content-type',116,101,120,116,47,104,116,109, 108]], [], [['content-encoding',105,100,101,110,116,105,116, 121]], [],[],[],[],[],[],[],[]}}}, undefined,"127.0.0.1",'REQDATA',undefined,undefined, {wm_log_data,undefined, {1322,989559,450145}, 'PUT', {6, {"content-length", {'Content-Length',"121"}, {"connection",{'Connection',"Keep-Alive"},nil,nil}, {"content-type", {'Content-Type', "application/json; charset=UTF-8"}, nil, {"host", {'Host',"localhost:8000"}, {"expect",{"Expect","100-Continue"},nil,nil}, {"user-agent", {'User-Agent', "Apache-HttpClient/4.0.1 (java 1.5)"}, nil,nil}}}}}, "127.0.0.1","/updatecustomer", {1,1}, 404,0,undefined,undefined,undefined}}, [],"/customer/cus/update","//customer/cus/update", {dict,0,16,16,8,80,48, {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}, {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}, [],".",500,1073741824,67108864,[],[], {6, {"content-length", {'Content-Length',"121"}, {"connection",{'Connection',"Keep-Alive"},nil,nil}, {"content-type", {'Content-Type',"application/json; charset=UTF-8"}, nil, {"host", {'Host',"localhost:8000"}, {"expect",{"Expect","100-Continue"},nil,nil}, {"user-agent", {'User-Agent',"Apache-HttpClient/4.0.1 (java 1.5)"}, nil,nil}}}}}, not_fetched_yet,false, {1,{"content-type",{"Content-Type","text/html"},nil,nil}}, <<>>, ["localhost"], 8000,[]}, undefined]}, {webmachine_resource,resource_call,3}, {webmachine_resource,do,3}, {webmachine_decision_core,resource_call,1}, {webmachine_decision_core,accept_helper,0}, {webmachine_decision_core,decision,1}, {webmachine_decision_core,handle_request,2}, {webmachine_mochiweb,loop,1}]}}

答えて

4

あなたはto_jsonを/ 2関数を定義する必要があります。例えば

to_json(RD, Result) -> 
    {mochijson:encode(Result), RD, Result}. 
+0

別のモジュールでto_jsonを定義しています。 – user1067665

+0

+1。ウェブマシンに関するいくつかのドキュメントを読んでください、それはさらに助けになると思います – danechkin

0

残念ながら私はイリヤによって答えにコメントするの評判を欠いています。

TLDR:あなたはそれを

長い答え

定義されたモジュールの名前の接頭辞 to_json:あなたの content_types_accepted/2コールを見てみると

I'm defining to_json in another module

は、あなたがto_jsonの中で存在するモジュールを指定されていません、したがってundefエラー。 Erlangの関数呼び出しは常にMFA - > module:function(arguments)であり、関数が同じモジュール内にある場合にのみモジュールを省略できます。 undefエラーを報告

{error, {error,undef, [{customer_update,to_json, ...

documentation on Erlang packages

0

を参照してください。このエラーを理解する鍵は一部です。これらの種類のエラーがで記述されています

http://www.erlang.org/doc/reference_manual/errors.html#id81244

そして、あなたはundefたちは未定義の機能を持っていることを意味していることがわかります。このエラーは、電話customer_update:to_json(..)が存在しないために発生しています。それがここにある問題です。

関連する問題