@@ -26,29 +26,29 @@ module JSON
2626 # user = User.find(1)
2727 # user.as_json
2828 # # => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
29- # # "created_at" => "2006/08/01 ", "awesome" => true}
29+ # # "created_at" => "2006-08-01T17:27:133.000Z ", "awesome" => true}
3030 #
3131 # ActiveRecord::Base.include_root_in_json = true
3232 #
3333 # user.as_json
3434 # # => { "user" => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
35- # # "created_at" => "2006/08/01 ", "awesome" => true } }
35+ # # "created_at" => "2006-08-01T17:27:13.000Z ", "awesome" => true } }
3636 #
3737 # This behavior can also be achieved by setting the <tt>:root</tt> option
3838 # to +true+ as in:
3939 #
4040 # user = User.find(1)
4141 # user.as_json(root: true)
4242 # # => { "user" => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
43- # # "created_at" => "2006/08/01 ", "awesome" => true } }
43+ # # "created_at" => "2006-08-01T17:27:13.000Z ", "awesome" => true } }
4444 #
4545 # Without any +options+, the returned Hash will include all the model's
4646 # attributes.
4747 #
4848 # user = User.find(1)
4949 # user.as_json
5050 # # => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
51- # # "created_at" => "2006/08/01 ", "awesome" => true}
51+ # # "created_at" => "2006-08-01T17:27:13.000Z ", "awesome" => true}
5252 #
5353 # The <tt>:only</tt> and <tt>:except</tt> options can be used to limit
5454 # the attributes included, and work similar to the +attributes+ method.
@@ -63,14 +63,14 @@ module JSON
6363 #
6464 # user.as_json(methods: :permalink)
6565 # # => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
66- # # "created_at" => "2006/08/01 ", "awesome" => true,
66+ # # "created_at" => "2006-08-01T17:27:13.000Z ", "awesome" => true,
6767 # # "permalink" => "1-konata-izumi" }
6868 #
6969 # To include associations use <tt>:include</tt>:
7070 #
7171 # user.as_json(include: :posts)
7272 # # => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
73- # # "created_at" => "2006/08/01 ", "awesome" => true,
73+ # # "created_at" => "2006-08-01T17:27:13.000Z ", "awesome" => true,
7474 # # "posts" => [ { "id" => 1, "author_id" => 1, "title" => "Welcome to the weblog" },
7575 # # { "id" => 2, "author_id" => 1, "title" => "So I was thinking" } ] }
7676 #
@@ -81,7 +81,7 @@ module JSON
8181 # only: :body } },
8282 # only: :title } })
8383 # # => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
84- # # "created_at" => "2006/08/01 ", "awesome" => true,
84+ # # "created_at" => "2006-08-01T17:27:13.000Z ", "awesome" => true,
8585 # # "posts" => [ { "comments" => [ { "body" => "1st post!" }, { "body" => "Second!" } ],
8686 # # "title" => "Welcome to the weblog" },
8787 # # { "comments" => [ { "body" => "Don't think too hard" } ],
@@ -93,11 +93,12 @@ def as_json(options = nil)
9393 include_root_in_json
9494 end
9595
96+ hash = serializable_hash ( options ) . as_json
9697 if root
9798 root = model_name . element if root == true
98- { root => serializable_hash ( options ) }
99+ { root => hash }
99100 else
100- serializable_hash ( options )
101+ hash
101102 end
102103 end
103104
0 commit comments