HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/default/doc/activemodel-6.1.4.1/ri/ActiveModel/Serializers/JSON/as_json-i.ri
U:RDoc::AnyMethod[iI"as_json:ETI"+ActiveModel::Serializers::JSON#as_json;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;	[I"FReturns a hash representing the model. Some configuration can be ;TI"passed through +options+.;To:RDoc::Markup::BlankLineo;
;	[	I"NThe option <tt>include_root_in_json</tt> controls the top-level behavior ;TI"Kof +as_json+. If +true+, +as_json+ will emit a single root node named ;TI"Rafter the object's type. The default value for <tt>include_root_in_json</tt> ;TI"option is +false+.;T@o:RDoc::Markup::Verbatim;	[I"user = User.find(1)
;TI"user.as_json
;TI"># => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"K#     "created_at" => "2006-08-01T17:27:133.000Z", "awesome" => true}
;TI"
;TI"4ActiveRecord::Base.include_root_in_json = true
;TI"
;TI"user.as_json
;TI"J# => { "user" => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"Z#                  "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true } }
;T:@format0o;
;	[I"MThis behavior can also be achieved by setting the <tt>:root</tt> option ;TI"to +true+ as in:;T@o;;	[	I"user = User.find(1)
;TI"user.as_json(root: true)
;TI"J# => { "user" => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"Z#                  "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true } }
;T;
0o;
;	[I"XIf you prefer, <tt>:root</tt> may also be set to a custom string key instead as in:;T@o;;	[	I"user = User.find(1)
;TI""user.as_json(root: "author")
;TI"L# => { "author" => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"Z#                  "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true } }
;T;
0o;
;	[I"KWithout any +options+, the returned Hash will include all the model's ;TI"attributes.;T@o;;	[	I"user = User.find(1)
;TI"user.as_json
;TI"># => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"K#      "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true}
;T;
0o;
;	[I"JThe <tt>:only</tt> and <tt>:except</tt> options can be used to limit ;TI"Jthe attributes included, and work similar to the +attributes+ method.;T@o;;	[
I"&user.as_json(only: [:id, :name])
;TI"2# => { "id" => 1, "name" => "Konata Izumi" }
;TI"
;TI"4user.as_json(except: [:id, :created_at, :age])
;TI":# => { "name" => "Konata Izumi", "awesome" => true }
;T;
0o;
;	[I"STo include the result of some method calls on the model use <tt>:methods</tt>:;T@o;;	[	I"'user.as_json(methods: :permalink)
;TI"># => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"K#      "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true,
;TI".#      "permalink" => "1-konata-izumi" }
;T;
0o;
;	[I"3To include associations use <tt>:include</tt>:;T@o;;	[
I"#user.as_json(include: :posts)
;TI"># => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"K#      "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true,
;TI"^#      "posts" => [ { "id" => 1, "author_id" => 1, "title" => "Welcome to the weblog" },
;TI"]#                   { "id" => 2, "author_id" => 1, "title" => "So I was thinking" } ] }
;T;
0o;
;	[I"=Second level and higher order associations work as well:;T@o;;	[I"&user.as_json(include: { posts: {
;TI"7                           include: { comments: {
;TI"@                                          only: :body } },
;TI"2                           only: :title } })
;TI"># => { "id" => 1, "name" => "Konata Izumi", "age" => 16,
;TI"K#      "created_at" => "2006-08-01T17:27:13.000Z", "awesome" => true,
;TI"a#      "posts" => [ { "comments" => [ { "body" => "1st post!" }, { "body" => "Second!" } ],
;TI"A#                     "title" => "Welcome to the weblog" },
;TI"S#                   { "comments" => [ { "body" => "Don't think too hard" } ],
;TI"?#                     "title" => "So I was thinking" } ] };T;
0:
@fileI")lib/active_model/serializers/json.rb;T:0@omit_headings_from_table_of_contents_below000[I"(options = nil);T@lFI"	JSON;TcRDoc::NormalModule00