Sha256: ba997e7b5d34f56369f43c787a8a7fb6e65abd867d1c6ecde0fcb3a04b3f1cf7
Contents?: true
Size: 1.32 KB
Versions: 9
Compression:
Stored size: 1.32 KB
Contents
module Logistics module Core class UnitsController < ApplicationController before_action :set_unit, only: [:update] def index units = Unit.includes(:unit_type) data = ApplicationRecord.as_json(units) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def create @unit = Unit.new(unit_params) if @unit.save response = Mks::Common::MethodResponse.new(true, 'Unit saved successfully!', @unit, nil, nil) else errors = Mks::Common::Util.error_messages @unit, 'Unit' response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end def update if @unit.update(unit_params) response = Mks::Common::MethodResponse.new(true, 'Unit updated successfully!', @unit, nil, nil) else errors = Mks::Common::Util.error_messages @unit, 'Unit' response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end private def set_unit @unit = Unit.find(params[:id]) end def unit_params params.require(:unit).permit(:abbreviation, :name, :unit_type_id, :rate_to_base) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems