diff --git a/README.markdown b/README.markdown index 07cde73b..6bed51f5 100644 --- a/README.markdown +++ b/README.markdown @@ -126,12 +126,12 @@ class PostSerializer < ActiveModel::Serializer # only let the user see comments he created. def comments - post.comments.where(:created_by => @scope) + post.comments.where(:created_by => options[:scope]) 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 `render :json` diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 5aef7812..55d303e0 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -91,7 +91,7 @@ module ActiveModel # end # # def author? - # post.author == scope + # post.author == options[:scope] # end # end # diff --git a/test/serializer_test.rb b/test/serializer_test.rb index 8d31d8dc..61895379 100644 --- a/test/serializer_test.rb +++ b/test/serializer_test.rb @@ -71,8 +71,8 @@ class SerializerTest < ActiveModel::TestCase end class CommentSerializer - def initialize(comment, scope, options={}) - @comment, @scope = comment, scope + def initialize(comment, options={}) + @comment = comment end def serializable_hash