module Logistics module Core class WarehouseRatePeriodsController < ApplicationController before_action :set_warehouse_rate_period, only: [:update] def index warehouse_id = params[:warehouse_id] @warehouse_rate_periods = WarehouseRatePeriod.where('warehouse_id' => warehouse_id) warehouse_rate_period_array =[] @warehouse_rate_periods.each { |wrp| warehouse_rate_period_array.push({:id => wrp.id, :name => wrp.warehouse.name, :from => wrp.from, :to => wrp.to, :rate_period => wrp.rate_period, :warehouse_id => wrp.warehouse_id }) } @response = Mks::Common::MethodResponse.new(true, nil, warehouse_rate_period_array, nil, nil) render json: @response end def create @warehouse_rate_period = WarehouseRatePeriod.new(warehouse_rate_period_params) if @warehouse_rate_period.valid? @warehouse_rate_period.save @response = Mks::Common::MethodResponse.new(true, 'Warehouse rate period saved successfully !',nil,nil,nil); render json: @response else errors = Mks::Common::Util.error_messages @warehouse_rate_period, 'WarehouseRatePeriod' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end def update if @warehouse_rate_period.update_attributes(warehouse_rate_period_params) @warehouse_rate_period.save @response = Mks::Common::MethodResponse.new(true, 'Warehouse rate period updated successfully !', nil, nil, nil) render json: @response else errors = Mks::Common::Util.error_messages @warehouse_rate_period, 'WarehouseRatePeriod' @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_warehouse_rate_period @warehouse_rate_period = WarehouseRatePeriod.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def warehouse_rate_period_params params.require(:warehouse_rate_period).permit(:warehouse_id, :rate_period, :from, :to) end end end end