How to consume JSON formatting with ruby's ActiveResource? -


ActiveRecord introduces a change in its default JSON output format. It runs from

  {"user": {some_junk}}  

  {some_junk}  

ActiveResource has apparently followed its leadership, JSON's as

  {some_junk}  

I am hoping to consume an active web service that emits

  {"user": {some_junk}}  

What is my ActiveResource: There is no way to tell the base class why? Here's my code.

  class user & lt; ActiveResource :: Base self.site = "http://example.com/" self.format =: json end  

Update : I'm leaving ActiveResource But for now it is broken, till no one knows the answer; Meanwhile, I was able to get the GET that I wanted

  needed 'httparty' # sudo gem install httparty result = httparty.get ('http://foo.com/bar ) .json ', Header = & gt; {"Foo" = & gt; "Bar"}) #The result is a hash made from JSON - Sweet!  

Yes, active data processing is currently slightly infrequent when it comes to data format is. / P>

In principle, it is the idea that you can write your own custom format modules (like JsonWithRootFormat ) depending on the module, and then in your model as your format You can specify:

  self.format =: json_with_root  

However, ActiveResource :: Base is not very format-anonymous - See if you are currently using XmlFormat , and if you are you pass through the root node.

So whatever you wanted by creating your own Format Module, and monkey-patching ActiveResource :: Base , but this is hardly the norm. I'm sure a patch slightly more format-agnewrit will be welcome to create base , though.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -