Skip to content

Instantly share code, notes, and snippets.

@xdite
Created August 6, 2014 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdite/055732e0e4ac7313f3c8 to your computer and use it in GitHub Desktop.
Save xdite/055732e0e4ac7313f3c8 to your computer and use it in GitHub Desktop.
customer_serializer.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :id, :name, :email, :phone, :store_credit, :credit_card, :receive_daily_emails, :is_driver, :addresses
def store_credit
object.total_available_store_credit.to_f
end
def credit_card
object.card_last_4
end
def is_driver
object.is_driver?
end
def receive_daily_emails
object.email_opt_in
end
def addresses
[]
end
def attributes
hash = super
hash["id"] = id.to_s
hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment