From ec60f7fb4be7213174f150318e418cdd8832a39b Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 16 Mar 2023 20:36:24 -0600 Subject: Añade código de ProductsController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/serializers/product_serializer.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/controllers/serializers/product_serializer.rb (limited to 'app/controllers/serializers') diff --git a/app/controllers/serializers/product_serializer.rb b/app/controllers/serializers/product_serializer.rb new file mode 100644 index 0000000..4a2158d --- /dev/null +++ b/app/controllers/serializers/product_serializer.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Serializers + # ProductSerializer + class ProductSerializer < BaseSerializer + extend ActionView::RoutingUrlFor + + attributes :name, :unitary_price, :bulk_price, :available_quantity, :categories + + attribute :picture do |object| + object.picture.url + end + + belongs_to :company, links: { + self: :url, + related: lambda(object) { + company_path(object.company) + } + } + end +end \ No newline at end of file -- cgit v1.2.3