Get the JSON gem for starters.
sudo gem install json
Then in your code:
require 'rubygems'
gem 'json'
require 'json'
-Rob
Rob Biedenharn http://agileconsultingllc.com
R...@AgileConsultingLLC.com
irb> require 'rubygems'
=> true
irb> gem 'json'
=> true
irb> require 'json'
=> true
irb> raw = "{\"first_name\":\"chamnap\",\"last_name\":\"chhorn\"}"
=> "{\"first_name\":\"chamnap\",\"last_name\":\"chhorn\"}"
irb> puts raw
{"first_name":"chamnap","last_name":"chhorn"}
=> nil
irb> JSON(raw)
=> {"first_name"=>"chamnap", "last_name"=>"chhorn"}
irb> cooked = JSON.parse(raw)
=> {"first_name"=>"chamnap", "last_name"=>"chhorn"}
irb> raw
=> "{\"first_name\":\"chamnap\",\"last_name\":\"chhorn\"}"
irb> cooked
=> {"first_name"=>"chamnap", "last_name"=>"chhorn"}
irb> raw.class
=> String
irb> cooked.class
=> Hash
irb> cooked["first_name"]
=> "chamnap"
irb> cooked[:first_name]
=> nil
Note that JSON.parse is going to return a normal Ruby Hash, not a
Rails ActiveSupport HashWithIndifferentAccess. You'll have to use
"first_name" as the key, not :first_name. Show the code that you're
trying to use that's pulling that whole string into a key of the
params hash.