Created
June 13, 2011 12:47
-
-
Save Amitesh/1022715 to your computer and use it in GitHub Desktop.
Get hash of a model object
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
# For Ruby on Rails | |
# It will give hash of given model object | |
model_obj.serializable_hash | |
# Another way to get hash of a model object | |
ActiveSupport::JSON.decode(model_obj.to_json) | |
For MultiJson issue use | |
https://github.com/intridea/multi_json | |
require 'multi_json' | |
MultiJson.load('{"abc":"def"}') #=> {"abc" => "def"} | |
MultiJson.load('{"abc":"def"}', :symbolize_keys => true) #=> {:abc => "def"} | |
MultiJson.dump({:abc => 'def'}) # convert Ruby back to JSON | |
MultiJson.dump({:abc => 'def'}, :pretty => true) # encoded in a pretty form (if supported by the coder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment