Robert Walker wrote: > 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.
Thanks for the helpful description. I have made that mistake before (not with cross-model associations, which are pretty easy to catch, but with a nested set when I tried to establish aunt and uncle relationships), and I am sure it's not the case here. Typically, I force jsonning associations to be manually declared in the options rather than enable them by default, but I did it here because I ruled it out as a cause. For the record, the to_json instance method on User doesn't invoke any associations. I am at a loss of how to troubleshoot this because: (1) The "works once then fails thereafter" behaviour is really weird. (2) I can't reproduce the error through the console (which produces the expected JSON output, user and all) -- 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.

