module Logistics module Core class SpecialIncrementContainerRatesController < ApplicationController before_action :set_container_increment, only: [:update] def index container_increments = SpecialIncrementContainerRate.all container_increments_array = [] container_increments.each { |ci| container_increments_array.push({:id => ci.id, :container_type_id => ci.container_type_id, :container_type_name => ci.container_type.name, :rate => ci.rate, :effective_date => ci.effective_date}) } response = Mks::Common::MethodResponse.new(true,nil,container_increments_array,nil,nil) render json: response end def create errors = [] container_increment = SpecialIncrementContainerRate.new(container_increment_params) if container_increment.valid? container_increment.save response = Mks::Common::MethodResponse.new(true, 'Container increment successfully created',nil,nil,nil) else errors << Mks::Common::Util.error_messages(container_increment, 'ContainerIncrement') response = Mks::Common::MethodResponse.new(false,nil,nil,errors,nil) end render json: response end def update @container_increment.update_attributes(container_increment_params) if @container_increment.save response = Mks::Common::MethodResponse.new(true, 'Container increment updated successfully !',nil,nil,nil) render json: response else errors = Mks::Common::Util.error_messages @container_increment, 'ContainerIncrement' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end private # Use callbacks to share common setup or constraints between actions. def set_container_increment @container_increment = SpecialIncrementContainerRate.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def container_increment_params params.require(:container_increment).permit(:id, :container_type_id, :rate, :effective_date) end end end end