1

I am trying to send json data from my rails controller but it always converts & into unicode \u0026. Is it possible to tell rails controller not to convert & into unicode \u0026 ?

Below is how my method looks like in controller (this is just dummy test method)

def send_detail
  render json: { data: "name?surname&otherdetail" } 
end

when I visit localhost:3000/tests/send_detail in postman, I get { "data":"name?surname\u0026otherdetail" }

How can I tell render method not to convert & into unicode character \u0026 ?. If possible I would like to preserve & only for this method rather than changing Rails config to not covert json data in unicode character for all rails application.

UPDATE

I am able to force rails not to covert & into unicode character by adding this line ActiveSupport.escape_html_entities_in_json = false but this changes the settings in all Rails application, which is not what I want. I only like to preserve & in one method.

1 Answer 1

2

You can manually convert it in the single action that you want it not to apply:

def send_detail
  render json: JSON.generate({ data: "name?surname&otherdetail" })
end

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.