Merge pull request #2260 from abhaynikam/2258-fix-class-name-documentation

[docs] Fix class name documentation
This commit is contained in:
Benjamin Fleischer 2018-06-22 16:51:55 -05:00 committed by GitHub
commit f3a19bd515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,7 +65,7 @@ Where:
- `virtual_value:` - `virtual_value:`
- `polymorphic:` defines if polymorphic relation type should be nested in serialized association. - `polymorphic:` defines if polymorphic relation type should be nested in serialized association.
- `type:` the resource type as used by JSON:API, especially on a `belongs_to` relationship. - `type:` the resource type as used by JSON:API, especially on a `belongs_to` relationship.
- `class_name:` used to determine `type` when `type` not given - `class_name:` the (String) model name used to determine `type`, when `type` is not given. e.g. `class_name: "Comment"` would imply the type `comments`
- `foreign_key:` used by JSON:API on a `belongs_to` relationship to avoid unnecessarily loading the association object. - `foreign_key:` used by JSON:API on a `belongs_to` relationship to avoid unnecessarily loading the association object.
- `namespace:` used when looking up the serializer and `serializer` is not given. Falls back to the parent serializer's `:namespace` instance options, which, when present, comes from the render options. See [Rendering#namespace](rendering.md#namespace] for more details. - `namespace:` used when looking up the serializer and `serializer` is not given. Falls back to the parent serializer's `:namespace` instance options, which, when present, comes from the render options. See [Rendering#namespace](rendering.md#namespace] for more details.
- optional: `&block` is a context that returns the association's attributes. - optional: `&block` is a context that returns the association's attributes.
@ -81,6 +81,7 @@ e.g.
```ruby ```ruby
has_one :bio has_one :bio
has_one :blog, key: :site has_one :blog, key: :site
has_one :blog, class_name: "Blog"
has_one :maker, virtual_value: { id: 1 } has_one :maker, virtual_value: { id: 1 }
has_one :blog do |serializer| has_one :blog do |serializer|
@ -114,6 +115,7 @@ e.g.
has_many :comments has_many :comments
has_many :comments, key: :reviews has_many :comments, key: :reviews
has_many :comments, serializer: CommentPreviewSerializer has_many :comments, serializer: CommentPreviewSerializer
has_many :comments, class_name: "Comment"
has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }] has_many :reviews, virtual_value: [{ id: 1 }, { id: 2 }]
has_many :comments, key: :last_comments do has_many :comments, key: :last_comments do
last(1) last(1)
@ -127,6 +129,7 @@ e.g.
```ruby ```ruby
belongs_to :author, serializer: AuthorPreviewSerializer belongs_to :author, serializer: AuthorPreviewSerializer
belongs_to :author, key: :writer belongs_to :author, key: :writer
belongs_to :author, class_name: "Author"
belongs_to :post belongs_to :post
belongs_to :blog belongs_to :blog
def blog def blog
@ -294,7 +297,7 @@ end
Whether you write the method as above or as `object.comments.where(created_by: scope)` Whether you write the method as above or as `object.comments.where(created_by: scope)`
is a matter of preference (assuming `scope_name` has been set). is a matter of preference (assuming `scope_name` has been set).
Keep in mind that the scope can be set to any available controller reference. This can be utilized to provide access to any other data scopes or presentation helpers. Keep in mind that the scope can be set to any available controller reference. This can be utilized to provide access to any other data scopes or presentation helpers.
##### Controller Authorization Context ##### Controller Authorization Context
@ -381,7 +384,7 @@ class PostsController < ActionController::Base
end end
end end
``` ```
Note that any controller reference which provides the desired scope is acceptable, such as another controller method for loading a different resource or reference to helpers. For example, `ActionController::API` does not include `ActionView::ViewContext`, and would need a different reference for passing any helpers into a serializer via `serialization_scope`. Note that any controller reference which provides the desired scope is acceptable, such as another controller method for loading a different resource or reference to helpers. For example, `ActionController::API` does not include `ActionView::ViewContext`, and would need a different reference for passing any helpers into a serializer via `serialization_scope`.
#### #read_attribute_for_serialization(key) #### #read_attribute_for_serialization(key)