activeresource - How to convert rails active resource object to hash? -
let's have active resource object fetched following:
x = resource.find(some_id)
and x in remote server has field h
complex nested hashes represented here nested active resource objects, accessing tedious task, possible convert h
hash? can make call resource.get(some_id) , result 1 big hash, risky resource -theoretically- may have changed between subsequent calls, there way convert active resource object hash ?
edit
for more clarification, suppose invoice record r[id=some_id] has attribute extras
, hash value: {:x=>1, :y=>2, :z=>{:a=>1, :b=>2}}
then when fetching record through active resource, following result extras field, -extracted response-:
"extras"=> #<app::invoice::extras:0x00000008202cb0 @attributes= {"x"=>1, "y"=>2, "z"=> #<app::invoice::extras::z:0x00000008201978 @attributes={"a"=>1, "b"=>2}, @persisted=true, @prefix_options={}>}, @persisted=true, @prefix_options={}>,
then how convert extras field ruby hash ?
json.parse(x.to_json)
did trick.
Comments
Post a Comment