Last active
September 15, 2015 14:14
-
-
Save novohispano/14960bb7638066820498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ItemSerializer < ActiveModel::Serializer | |
attributes :id, | |
:name, | |
:description, | |
:image_url, | |
:created_at, | |
:updated_at, | |
:order_count | |
has_many :order_items | |
has_many :orders, through: :order_items | |
def order_count | |
object.orders.count | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
json.extract! @item, :id, | |
:name, | |
:description, | |
:created_at, | |
:updated_at | |
json.order_count @item.orders.count | |
json.orders @item.orders, :amount, | |
:user_id, | |
:created_at, | |
:updated_at |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment