Get Component Attribute value to json in Ruby On Rails

See: AttributeDictionary#each_pair

When the JSON library has been required:

require "json"

… Then, …basically:

def get_json_from_dict( obj, dict_name )
  d = obj.attribute_dictionary(dict_name,false)
  return false if d.nil?
  h = {} # create a hash
  d.each_pair {|k,v| h[k]=v }
  "{ #{dict_name} : #{h.to_json} }"
end

Ref: Index of Classes & Methods in json: Ruby Standard Library Documentation (Ruby 2.2.4)