In Ruby on Rails, how to render JSON?

大城市里の小女人 提交于 2019-12-13 10:25:12

问题


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

  - response.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?


回答1:


= render :json => @object 

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



来源:https://stackoverflow.com/questions/3367246/in-ruby-on-rails-how-to-render-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!