2011-12-12 43 views

回答

32

如果你想放置或張貼到一個URL也有這方面的方法。您可以複製/因爲它們顯示在你的Rails生產日誌準確粘貼參數:

app.post('/foo', {"this" => "that", "items" => ["bar", "baz"]}) 
app.put('/foo', {"this" => "that", "items" => ["bar", "baz"]}) 

如果要發送自定義標題,您可以添加一個可選的第三個參數:

app.post('/foo', {:this => "that", :items => ["bar", "baz"]}, {"X-Do-Something" => "yes"}) 

任何get/post/put/delete方法將在控制檯上顯示它們的完整日誌輸出,供您檢查。如果你想獲得信息,如響應主體返回HTTP狀態或響應頭這些都太容易:

app.response.body 

app.response.status 

app.response.headers.inspect 

來源:http://andyjeffries.co.uk/articles/debug-level-logging-for-a-single-rails-production-request