Steven Xu wrote:
> def to_json(options = {})
> {
> :id => id,
> :body => body,
> :parent_id => parent_id,
> :created_at => created_at,
> :updated_at => updated_at,
> :user => user ### the line in question
> }.to_json(options)
> end
Let's think about what the call to to_json on the Hash is doing...
Each key/value pair will be sent the message to_json. I assume the Hash
takes care of providing the JSON representation of the more basic types
like String, Fixnum, etc. But, what about when to_json gets sent to the
user object.
Given that Item has_one :user then likely User has_many :items. The item
your working with may be contained within an array of user, if user's
to_json includes items. This might explain how you end up with a "stack
level too deep."
Since I don't know how your User model is behaving I can't say for sure
that is the problem, but it is something to consider.
--
Posted via http://www.ruby-forum.com/.
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.