Skip to content

Commit 02ea553

Browse files
committed
fix typo in my previous message and add documentation for default behavior
1 parent 2926ed6 commit 02ea553

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

guides/concepts/resources.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ end
113113
{% endhighlight %}
114114

115115
When guarding the `:readable` flag, the method can optionally accept the
116-
model instance and the of the attribute being serialized as arguments:
116+
model instance and the name of the attribute being serialized as arguments:
117117

118118
{% highlight ruby %}
119119
attribute :name, :string, readable: :allowed?
@@ -142,6 +142,18 @@ self.attributes_sortable_by_default = false # default true
142142
self.attributes_schema_by_default = false # default true
143143
{% endhighlight %}
144144

145+
As for resource defined guards, you can pass a symbol to guard the
146+
behavior globally. This can be used to globally delegate access control to a
147+
dedicated system.
148+
149+
{% highlight ruby %}
150+
self.attributes_readable_by_default = :attribute_readable? # default true
151+
152+
def attribute_readable?(model_instance, attribute_name)
153+
PolicyChecker.new(model_instance).attribute_readable?(attribute_name)
154+
end
155+
{% endhighlight %}
156+
145157
{% include h.html tag="h4" text="2.3 Customizing Display" a="customizing-display" %}
146158

147159
Pass a block to `attribute` to customize display:

0 commit comments

Comments
 (0)