mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Remove left over references to scope instance variable
This commit is contained in:
parent
56b61b1532
commit
81fddb55d3
@ -126,12 +126,12 @@ class PostSerializer < ActiveModel::Serializer
|
|||||||
|
|
||||||
# only let the user see comments he created.
|
# only let the user see comments he created.
|
||||||
def comments
|
def comments
|
||||||
post.comments.where(:created_by => @scope)
|
post.comments.where(:created_by => options[:scope])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
In a serializer, `@scope` is the current authorization scope (usually
|
In a serializer, `options[:scope]` is the current authorization scope (usually
|
||||||
`current_user`), which the controller gives to the serializer when you call
|
`current_user`), which the controller gives to the serializer when you call
|
||||||
`render :json`
|
`render :json`
|
||||||
|
|
||||||
|
|||||||
@ -91,7 +91,7 @@ module ActiveModel
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def author?
|
# def author?
|
||||||
# post.author == scope
|
# post.author == options[:scope]
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
|||||||
@ -71,8 +71,8 @@ class SerializerTest < ActiveModel::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
class CommentSerializer
|
class CommentSerializer
|
||||||
def initialize(comment, scope, options={})
|
def initialize(comment, options={})
|
||||||
@comment, @scope = comment, scope
|
@comment = comment
|
||||||
end
|
end
|
||||||
|
|
||||||
def serializable_hash
|
def serializable_hash
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user