Created
July 21, 2011 02:16
-
-
Save pjkelly/1096376 to your computer and use it in GitHub Desktop.
JSON Encoding in Rails 1.2.x
This file contains hidden or 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
# In Rails 1.2.x, the default JSON encoder doesn't quote | |
# attributes. To force quoting, set the following option | |
# to false. From the ActiveSupport::JSON docs: | |
# | |
# When +true+, Hash#to_json will omit quoting string or symbol keys | |
# if the keys are valid JavaScript identifiers. Note that this is | |
# technically improper JSON (all object keys must be quoted), so if | |
# you need strict JSON compliance, set this option to +false+. | |
# mattr_accessor :unquote_hash_key_identifiers | |
# @@unquote_hash_key_identifiers = true | |
ActiveSupport::JSON.unquote_hash_key_identifiers = false | |
collection = Product.find(:all).collect { |p| p.attributes }.to_json | |
puts collection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment