开发者

In Ruby on Rails, how to render JSON?

开发者 https://www.devze.com 2023-01-09 17:09 出处:网络
I tried the following to respond to AJAX and it works (in HAML): - response.content_type = \"application/json\"

I tried the following to respond to AJAX and it works (in HAML):

  - response.content_type = "application/json"
  = render :text => array_data.to_json

but

  - resp开发者_如何学运维onse.content_type = "application/json"
  = render :json => array_data.to_json

doesn't work. I thought I could use

  = render :text => array_data.to_json

instead of the first 2 lines at the top?


= render :json => @object 

(u don't need to use .to_json method)

0

精彩评论

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

关注公众号