I’m using the following in rails to push to node.js:
NodePush[].trigger('unit', 'join', {:id =>record.user_id, :name => record.user.name}, record.unit_id)
Problem I’m having is console is logging the results as:
{"id":7154,"name":"Medallions"}
What I want is for the console to output an object like so:
Object
id: 7154
name: "Medallions"
Any suggestions on how to update the rails code to create an object? Thanks
When you push data from Rails to Node, you’re pushing JSON. If you want to see the JavaScript object that Node reconstitutes on its end, you need to log the object after it’s parsed, or alternately, explicitly call
JSON.parse(str)when you log the object to the console (wherestris the JSON string).