我創建了一個簡單的api,該響應使用json。當我嘗試從瀏覽器中調用它時,我得到了相應的json響應,但是當我嘗試從actionscript遠程調用它時,似乎它會像調用方法那樣調用json。這是控制器的動作:Rails respond_with輸出json並試圖將其稱爲方法
def matcher
@conn = Connection.first
if(@conn)
respond_with({:conn => @conn, :status => :ok}.to_json)
else
respond_with({:status => :no_content}.to_json)
end
end
這是當它得到
Started POST "/connection/matcher/1.json" for 127.0.0.1 at 2010-11-11 22:57:24 -0800
Processing by ConnectionsController#matcher as JSON
Parameters: {"stratus_string"=>"bad1de003755eaa01a2920f0091d0dd66beaf2d34f651b09a578afb1b54e5686", "user_id"=>"1", "id"=>"1"}
Connection Load (0.5ms) SELECT "connections".* FROM "connections" LIMIT 1
Completed in 24ms
NoMethodError (undefined method `{"conn":{"created_at":"2010-11-12T06:55:13Z","id":6,"stratus_string":"474735730abe81d7622d377bd0bf816c3f94721ece3eddf670bf3a74b1c2356c","updated_at":"2010-11-12T06:55:13Z","user_id":1},"status":"ok"}_url' for #<ConnectionsController:0x000001030e4350>):
app/controllers/connections_controller.rb:7:in `matcher'
爲什麼軌試圖執行JSON響應呼叫服務器的響應?我不明白。
UPDATE:
這裏是ActionScript代碼,使通話,雖然我不明白爲什麼它的確與衆不同。
this.restService = new HTTPService();
this.restService.url = "http://localhost:3000/connection/matcher/1.json";
this.restService.method = "POST";
this.restService.addEventListener("result", onRestResult);
this.restService.addEventListener("fault", onRestFault);
var request:Object = new Object();
request.user_id = user;
request.stratus_string = id;
this.restService.cancel();
this.restService.send(request);
謝謝!
你能不能發佈你的js代碼? – Sergey 2010-11-12 08:52:39
我沒有js代碼。調用者在動作 – Danny 2010-11-12 09:15:31
更新:它只發生在POST沒有GET – Danny 2010-11-12 15:10:21