You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 is clearly not the behaviour we would want. Why does this happen?
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.
The text was updated successfully, but these errors were encountered: