alexeyb
alexeyb

Reputation: 153

how to change json format on rails

I'm new to rails, can somebody help me with json format that rails 3.2.2 produce I want to know where and how i need to make changes to affect my json otput. For example when i click http://localhost:3000/customers.json i got output like this

[{"created_at":"2012-03-17T16:10:59Z","id":1,"name":"Jon","phone":"59665","updated_at":"2012-03-17T16:10:59Z"}]

, but i need ==>

[{"customer":{{"created_at":"2012-03-17T16:10:59Z","id":1,"name":"Jon","phone":"59665","updated_at":"2012-03-17T16:10:59Z"}}]

Thanks in advance.

Upvotes: 1

Views: 509

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

You'll want to set ActiveRecord::Base.include_root_in_json = true

Try setting that in an initializer (config/initializers), restarting your server. You should see the root object appear in your json.

Upvotes: 4

Related Questions