Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add/rails.rb incompatible with rails 2.3.x #31

Closed
devwout opened this issue May 25, 2010 · 3 comments
Closed

add/rails.rb incompatible with rails 2.3.x #31

devwout opened this issue May 25, 2010 · 3 comments

Comments

@devwout
Copy link

devwout commented May 25, 2010

require 'json/add/rails'
class Person < ActiveRecord::Base ; end
Person.new.to_json # => {'attributes' => ..., 'attributes_cache' => ..., ...}

This is clearly not the behaviour we would want. Why does this happen?

# active_record/base.rb
class ActiveRecord::Base
  def to_json
    super
  end
end
# active_support/json.rb
class Object
  def to_json(options = nil)
    ActiveSupport::JSON.encode(as_json(options))
  end
end

When requiring json/add/rails.rb after ActiveSupport, the to_json method is overridden and rails json serialization breaks. Is there a reason this file still exists? It seems to just copy functionality that is already present in ActiveSupport.

Encountered this issue using nanite, which requires this file in the json library.

@roidrage
Copy link

Gotta say, I've been using Nanite with Rails 2.3 for months, never had an issue with it, though I've also dumped ActiveRecord back then. It may copy functionality of AS, but it stays clear of not having a dependency on it.

@devwout
Copy link
Author

devwout commented May 25, 2010

Issue was probably introduced by http://github.com/rails/rails/commit/55501b9f6ab46d45db04a81956579402511ad092 which was released in rails 2.3.4.

@devwout
Copy link
Author

devwout commented May 25, 2010

The require of json/add/rails happens in nanite-rails and not nanite itself. Stupid mistake. This does not change the problem with json/add/rails however.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants