Rails 3 respond_with json question

Hello,

Having trouble with generating some json. I am trying to render an
single active record result to json like this:

@data = User.find(1)
respond_with(@data, :include => :status)

The json result is:

{
-user: {
address: null
email: “[email protected]
first_name: “Test”
last_name: “Man”
status_id: 1
username: “testguy”
status: { }
}
}

So whats the problem? The problem is that the :include=>:status seems
to not bring over the relation. In my User model I have a
belongs_to :status. How do i get this to work on a single result set?

When I do this:

@data = User.where("id = 1")
respond_with(@data, :include => :status)

The relation shows in the json result set fine this way. But its
within an array of objects, which i do not want.

Any ideas?

On May 10, 2011, at 9:02 PM, mikefuzz wrote:

Hello,

Having trouble with generating some json. I am trying to render an
single active record result to json like this:

@data = User.find(1)

What happens (is there any difference?) if you do this:

@data = User.find(1, :include => :status)

Walter

That doesn’t work. Then it displays this:

{
-user: {
address: null
email: “[email protected]
first_name: “Test”
last_name: “Man”
status_id: 1
username: “test”
}
}