Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

#to_json not working because always being called on Object

#2690

to_json is aliased from rails_to_json on the Object class, while in all other classes (String, Hash, etc.), only rails_to_json is defined.

The overriden rails_to_json methods do not automatically override to_json too.

In the master branch the implementation is a bit different and this is not present, but it is in 2-3-stable.

My patch just defines to_json in Object to call rails_to_json instead of aliasing it.

Reported by Caio Chassot · May 21st, 2009 @ 06:24 PM

State: resolved
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Caio Chassot
  2. Caio Chassot
  3. Caio Chassot
    Caio Chassot
    • Tag changed from 2-3-stable, active_support, json to 2-3-stable, active_support, json, patch

    May 21st, 2009 @ 06:42 PM

  4. Caio Chassot
    Caio Chassot

    Here's what is currently happen, without the patch:

    When you call to json on any ruby object, you get Object#rails_to_json called, which will return a hash of instance variables, so for most objects, like strings, you get an empty hash: "{}"

    May 21st, 2009 @ 06:45 PM

  5. Caio Chassot
    Caio Chassot

    adding git-formatted patch

    May 21st, 2009 @ 06:48 PM

  6. Hongli Lai
    Hongli Lai

    Caio Chassot's patch does not seem to correctly pass arguments to #rails_to_json. This patch should fix the problem.

    May 24th, 2009 @ 10:47 AM

  7. CancelProfileIsBroken
    CancelProfileIsBroken
    • Assigned user set to Pratik

    +1 on Hongli's patch. Fixes multiple failures in the Rails test suite that were introduced with http://github.com/rails/rails/commit/2b5e4f38f5d7af912770f8a298ba2e... and currently preventing a clean Rails 2.3 build.

    May 24th, 2009 @ 12:31 PM

  8. Pratik