2010-11-02 152 views
0

我已經在我的rails 3控制器中寫了一個簡單的jquery響應,我只想測試看看返回的結果(不是自動測試)。如何從我的rails控制器調試/測試json響應?

我的代碼如下所示:

class AppointmentsController < ApplicationController 
def jsonlist 
    @appointments = Appointment.find(:all) 
    render :json => @appointments 
end 

我可以訪問此從像網址:http://localhost:3000/appointments/jsonlist

當我嘗試,我得到這個錯誤:

Couldn't find Appointment with ID=jsonlist

回答

3

你得到不出現來自該操作的誤差,這似乎是在你的路由衝突的任何已定義爲您的show操作。在爲show定義路線之前,嘗試定義您的路線爲jsonlist

0

調試從控制器的JSON響應

render json: JSON.pretty_generate(JSON.parse(@appointments.to_json)) 
相關問題