我可以使用JSON对象和jQuery-Rails(jQuery库加上一个特殊的rails.js文件)对Rails(3)进行典型的Ajax调用.
In one controller, though, I want to RETURN some JSON in an erb template (create.js.erb) after an AJAX call.
我try 了控制器中的所有组合(@object.to_json、‘[{"content":"hello world"}]’等).和模板本身(JSON.parse()、单引号、双引号等),但对象继续以如下方式呈现:
'[{"groups":{},"created_at":"2010-09-21T03:49:34Z" ...
and as a result, my jQuery code cannot parse it and I get errors.
How do I need to prep my object in the controller, and what erb syntax do I need in the view for it to render as a valid JSON object?
非常感谢!