mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
String/Lambda support for conditional attributes/associations
This commit is contained in:
@@ -80,6 +80,10 @@ end
|
||||
|
||||
```ruby
|
||||
has_one :blog, if: :show_blog?
|
||||
# you can also use a string or lambda
|
||||
# has_one :blog, if: 'scope.admin?'
|
||||
# has_one :blog, if: -> (serializer) { serializer.scope.admin? }
|
||||
# has_one :blog, if: -> { scope.admin? }
|
||||
|
||||
def show_blog?
|
||||
scope.admin?
|
||||
|
||||
Reference in New Issue
Block a user