module Mks module Edm class EquipmentComponentsController < ApplicationController before_action :set_equipment_component, only: %i[show update] def index @equipment_components = EquipmentComponent.where(equipment_item_id: params[:id]) render json: @equipment_components end def show render json: @equipment_component end def create @equipment_component = EquipmentComponent.new(equipment_component_params) if @equipment_component.save render json: @equipment_component, status: :created, location: @equipment_component else render json: @equipment_component.errors, status: :unprocessable_entity end end def update if @equipment_component.update(equipment_component_params) render json: @equipment_component else render json: @equipment_component.errors, status: :unprocessable_entity end end private def set_equipment_component @equipment_component = EquipmentComponent.find(params[:id]) end def equipment_component_params params.require(:equipment_component).permit(:id, :name, :serial_no, :equipment_item_id) end end end end