# Create ActiveRecord from Javascript object via JSON

**URL:** <https://www.ruby-forum.com/t/create-activerecord-from-javascript-object-via-json/156929>\
**Category:** Rails\
**Created:** [January 5, 2009, 1:37pm UTC](https://www.ruby-forum.com/t/create-activerecord-from-javascript-object-via-json/156929 "2009-01-05T13:37:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reactorman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@reactorman](https://www.ruby-forum.com/u/reactorman)\
**Post date:** [January 5, 2009, 1:37pm UTC](https://www.ruby-forum.com/t/create-activerecord-from-javascript-object-via-json/156929/1 "2009-01-05T13:37:51Z")

</div>

HI All,  
I am trying to create an ActiveRecord object from a javascript object  
via JSON. However the controller fails to set the variables passed  
within the ActiveRecord object.

As an example, a person object has two fields: firstname and lastname.

The JSON generated by the JSON.stringify function of the [JSON.org](http://JSON.org)  
library produces:  
{“firstname” : “Joe” , “lastname” : “Bloggs”}

However the controller requires:

{ “Person” : {“firstname” : “Joe” , “lastname” : “Bloggs”} }

I am aware that in the normal course of events (for HTTP requests) the  
parameters for the request are nested under the class name of the model  
being created.

What would be the neatest way for the controller to process the JSON  
requests as generated? Or alternatively how do you generate “correct”  
JSON from Javascript objects for passing to your controllers?

TIA,  
Adam
