JSON encoding wrongly escaped (Rails 3, Ruby 1.9.2)

后端 未结 7 1498
醉梦人生
醉梦人生 2020-12-01 08:14

In my controller, the following works (prints \"oké\")

puts obj.inspect

But this doesn\'t (renders \"ok\\u00e9\")

render :j         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 08:45

    I have got a very tricky way to solve this problem. Well, if to_json did not allow you to have the correct code, then you could directly try to write :

    render text: tags
    

    render json: tags or render json: tags.to_json will always auto transfer the encoding style, but if you use render text:tags, then the string will stay as it is. And I think jQuery could still recognize the data.

提交回复
热议问题