Help for hash.to_json

hi , all
under rails 2.0

[email protected]:~/workspace/killer$ ruby script/console
Loading development environment (Rails 2.0.1)

{:user=>“aotianlong”}.to_json
=> “{“user”: “aotianlong”}”

user = User.find :first
=> #<User id: 1, uname: “aotianlong”>

user.to_json
=> “{“attributes”: {“id”:1,“uname”: “aotianlong”}}”

{:user=>user}.to_json
ArgumentError: wrong number of arguments (1 for 0)
from
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoding.rb:22:in
to_json' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoding.rb:22:insend’
from
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoding.rb:22:in
encode' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoding.rb:32:inraise_on_circular_reference’
from
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoding.rb:21:in
encode' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoders/hash.rb:45:into_json’
from
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoders/hash.rb:44:in
map' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoders/hash.rb:44:into_json’
from
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/core_ext/object/misc.rb:28:in
returning' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.1/lib/active_support/json/encoders/hash.rb:43:into_json’
from (irb):4

how let {:user=>user}.to_json work correct?

thanks for reply.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs