如何调试/测试来自 Rails 控制器的 json 响应?
我在我的 Rails 3 控制器中编写了一个简单的 jquery 响应,我只想测试一下返回的结果(不是自动化测试)。
我的代码如下所示:
class AppointmentsController < ApplicationController
def jsonlist
@appointments = Appointment.find(:all)
render :json => @appointments
end
我可以从如下 URL 访问此代码: http://localhost:3000/appointments/jsonlist< /a>?
当我尝试时,我收到此错误:
找不到预约对象 ID=jsonlist
I have written a simple jquery response in my rails 3 controller, I just want to test to see the result this returns (not automated testing).
My code looks like this:
class AppointmentsController < ApplicationController
def jsonlist
@appointments = Appointment.find(:all)
render :json => @appointments
end
Can I access this from a URL like: http://localhost:3000/appointments/jsonlist?
When I try, I get this error:
Couldn't find Appointment with
ID=jsonlist
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您收到的错误似乎不是来自该操作,它似乎是您定义为
show
操作的路由冲突。在定义show
的路由之前,尝试定义jsonlist
的路由。The error you're getting does not appear to come from that action, it appears to be a conflict in your routes for whatever you have defined as your
show
action. Try defining your route forjsonlist
before you define your route forshow
.调试来自控制器的 json 响应
to debug a json response from your controller