How do I render an attribute only if some condition is true?
For example, I want to render User\'s token attribute on create action.
you can override the attributes method, here is a simple example:
attributes
class Foo < ActiveModel::Serializer attributes :id def attributes(*args) hash = super hash[:last_name] = 'Bob' unless object.persisted? hash end end