I'm using
[acts_as_commentable_with_threading](http://github.com/elight/acts_as_commentable_with_threading/),
and it worked fine until I tried to overwrite the to_json function to
include more details about the associated user.

Here's part of the comment class (which was originally defined in the
plugin, but I moved it to the models folder, a move which seems not to
affect the error):

    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

When the line is included, the server responds accordingly the first
time you request the resource, but every subsequent request (a
particular oddity), I get:

SystemStackError (stack level too deep):
  app/models/comment.rb:21:in `to_json'
  C:1:in `__send__'
  C:1:in `encode'
  C:1:in `__send__'
  C:1:in `encode'
  app/models/item.rb:61:in `to_json'
  app/controllers/items_controller.rb:20
  app/controllers/items_controller.rb:18:in `show'
  C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
  C:/Ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

Removing the line prevents the error from showing up.

I call associations in to_json elsewhere in the application with no
issues.
-- 
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.

Reply via email to