How to deal with HTML entities in Rails to_json output?

后端 未结 2 832
终归单人心
终归单人心 2021-01-18 04:16

I\'m writing an app that uses Rails on the backend and javascript/backbone on the frontend. I\'m trying to bootstrap some rails models into my javascript. Specifically, I\'

2条回答
  •  醉酒成梦
    2021-01-18 04:41

    The question is solved by my comment, just for the record:

    Rails escapes strings that are printed using <%= 'string' %>. By this, it is save to ouput user data. So, if you don't want Rails to escape the output, you have to tell Rails explicitly by using raw('string').

    In your code, that would be: <%= raw(@courses.to_json) %>

提交回复
热议问题