3

I have a query regarding rails render method.

If I have something like->

hashObj = {"a"=> 1, "b"=>2}
render json: hashObj

then I know that render method will internally call JSON.dump(hashObj) to get the json to render.

However I want to use my own custom library (e.g. Oj) to create json, can I do something like this:

hashObj = {"a"=> 1, "b"=>2}
render json: Oj.dump(hashObj, mode: :compat)

How will render method behave here ? Will it check that we are already passing it a json string and hence it does not need to call JSON.dump now ?

2
  • Why don't you try it out how render behaves? Commented May 22, 2014 at 19:31
  • I did, but its a bit confusing, hence wanted to clarify it further here on StackOverflow. Commented May 23, 2014 at 7:26

1 Answer 1

1

You're right, Rails won't attempt to convert what ever you pass to the json option if it's some kind of a string, as you can see here.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.