This project is archived and is in readonly mode.

#2083 ✓invalid
NeoRiddle

to_json problems with Array of 'models'

Reported by NeoRiddle | February 26th, 2009 @ 09:53 AM | in 3.x

Hi!

I have this code in controller:


class ChapSixController < ApplicationController
  def map
    @towers = Tower.all.to_json
  end
end

I think there is a problem with transformming arrays with some model object (ActiveRecord::Base objects) by calling 'to_json' method. But testing this with another object like strings, numbers, etc. it does not happen.

Here you have the exception trace:


wrong number of arguments (1 for 0)

/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:in `to_json'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:in `send'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:21:in `encode'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:31:in `raise_on_circular_reference'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoding.rb:20:in `encode'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoders/enumerable.rb:10:in `to_json'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoders/enumerable.rb:10:in `map'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/json/encoders/enumerable.rb:10:in `to_json'
app/controllers/chap_six_controller.rb:3:in `map'

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages