Sha256: 22629c52a9575ee6cdd7adceed98135762249918d0682ad78e9f684bfd234656
Contents?: true
Size: 1.59 KB
Versions: 3
Compression:
Stored size: 1.59 KB
Contents
require_dependency "bouquet/gate/application_controller" module Bouquet class Gate::ProductsController < ApplicationController before_action :set_product, only: [:show, :update, :destroy] # GET /products def index products = Bouquet::Product.all @products = products.map do |product| { id: product.id, name: product.name, price: product.price, assemblies: product.assemblies.map do |assembly| { material_name: assembly.material.name, quantity: assembly.quantity } end } end render json: @products end # GET /products/1 def show render json: @product end # POST /products def create @product = Bouquet::Product.new(product_params) if @product.save render json: @product, status: :created, location: @product else render json: @product.errors, status: :unprocessable_entity end end # PATCH/PUT /products/1 def update if @product.update(product_params) render json: @product else render json: @product.errors, status: :unprocessable_entity end end # DELETE /products/1 def destroy @product.destroy end private # Use callbacks to share common setup or constraints between actions. def set_product @product = Bouquet::Product.find(params[:id]) end # Only allow a trusted parameter "white list" through. def product_params params.require(:product).permit(:name) end end end
Version data entries
3 entries across 3 versions & 1 rubygems