Skip to content

Instantly share code, notes, and snippets.

@daneb
Last active February 17, 2016 09:43
Show Gist options
  • Save daneb/d870304d317243447d2d to your computer and use it in GitHub Desktop.
Save daneb/d870304d317243447d2d to your computer and use it in GitHub Desktop.
Hanami JSON Oddity I don't understand
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?
@daneb
Copy link
Author

daneb commented Feb 17, 2016

From Gitter:
accuser 11:40
@daneb The string returned by the view is considered unsafe, and is being escaped. To avoid this, use _raw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment