开发者

How can I debug/test a json response from my rails controller?

开发者 https://www.devze.com 2023-01-22 19:37 出处:网络
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).

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 jsonli开发者_高级运维st
  @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


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 for jsonlist before you define your route for show.


to debug a json response from your controller

render json: JSON.pretty_generate(JSON.parse(@appointments.to_json))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号