# Json response with belongs\_to

**URL:** <https://www.ruby-forum.com/t/json-response-with-belongs-to/187522>\
**Category:** Rails\
**Created:** [April 24, 2010, 7:43pm UTC](https://www.ruby-forum.com/t/json-response-with-belongs-to/187522 "2010-04-24T19:43:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabiokr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/cdc98d/32.png) [@fabiokr](https://www.ruby-forum.com/u/fabiokr)\
**Post date:** [April 24, 2010, 7:43pm UTC](https://www.ruby-forum.com/t/json-response-with-belongs-to/187522/1 "2010-04-24T19:43:23Z")

</div>

Hi all,

Supponsing I have this:

class Post \< ActiveRecord::Base  
end

class Comment \< ActiveRecord::Base  
belongs\_to :post  
end

How can I make (on Rails 3) on the CommentsController to respond with  
a json object including the related Post?

Thanks!

---

<div class="post-metadata">

**Author:** ![fabiokr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/cdc98d/32.png) [@fabiokr](https://www.ruby-forum.com/u/fabiokr)\
**Post date:** [April 25, 2010, 4:42pm UTC](https://www.ruby-forum.com/t/json-response-with-belongs-to/187522/2 "2010-04-25T16:42:52Z")

</div>

Anyone?

What I want is to inform Rails somehow that the json I want for the  
comment should also contain information from the Post.
