Last active
February 17, 2016 09:43
-
-
Save daneb/d870304d317243447d2d to your computer and use it in GitHub Desktop.
Hanami JSON Oddity I don't understand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The repo for the code is at (pretty basic): | |
https://github.com/daneb/hanami_json_oddity | |
I understand the best approach is to use a controller here and not the view. | |
But I am trying to understand the behaviour of what I am seeing. | |
In my view, when I take my hash and .to_json it, the final result from the HTTP GET is: | |
{ status: "success", data: { get: { message: 'Created new session via registration', session_id: session_id } }}.to_json | |
{"status":"success","data":{"get":{"message":"Created new session via registration","session_id":12}}} | |
When I remove .to_json from the view and apply it to the hash in the template it works: | |
<%= get_sample_hash.to_json %> | |
{ | |
"data": { | |
"get": { | |
"message": "Created new session via registration", | |
"session_id": 12 | |
} | |
}, | |
"status": "success" | |
} | |
What am I missing? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Gitter:
accuser 11:40
@daneb The string returned by the view is considered unsafe, and is being escaped. To avoid this, use _raw.