Class: Logistics::Core::UnitsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/units_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/logistics/core/units_controller.rb', line 13

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

#indexObject



6
7
8
9
10
11
# File 'app/controllers/logistics/core/units_controller.rb', line 6

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

#updateObject



24
25
26
27
28
29
30
31
32
# File 'app/controllers/logistics/core/units_controller.rb', line 24

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