Module: ControllerCommon

Extended by:
ActiveSupport::Concern
Included in:
Logistics::Core::ClientsController, Logistics::Core::CustomsOfficesController
Defined in:
app/controllers/concerns/controller_common.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/concerns/controller_common.rb', line 10

def create
  model = get_model.build(model_params)

  if model.save
    response=Mks::Common::MethodResponse.new(true, "#{get_humanized_name} saved successfully!", nil, nil)
  else
    errors = Mks::Common::Util.error_messages(model, "#{get_humanized_name}")
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, 0)
  end
  render json: response
end

#updateObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/concerns/controller_common.rb', line 22

def update
  if @model.update(model_params)
    response = Mks::Common::MethodResponse.new(true, "#{get_humanized_name} updated successfully!", @model, nil, nil)
  else
    errors = Mks::Common::Util.error_messages(@model, "#{get_humanized_name}")
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end