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

   respond_with(@data, :include => :status)

The json result is:

{
-user: {
address: null
email: "t...@email.com"
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?

-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails- t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .


--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to