module Logistics module Core class SpecialIncrementContentRatesController < ApplicationController before_action :set_content_increment, only: [:update] def index content_increments = SpecialIncrementContentRate.all content_increments_array = [] content_increments.each { |ci| content_increments_array.push({:id => ci.id, :content_type_id => ci.content_type_id, :content_type_name => ci.content_type.name, :rate => ci.rate, :effective_date => ci.effective_date}) } response = Mks::Common::MethodResponse.new(true,nil,content_increments_array,nil,nil) render json: response end def create errors = [] content_increment = SpecialIncrementContentRate.new(content_increment_params) if content_increment.valid? content_increment.save response = Mks::Common::MethodResponse.new(true, 'Content increment successfully created',nil,nil,nil) else errors = Mks::Common::Util.error_messages(content_increment, 'ContentIncrement') response = Mks::Common::MethodResponse.new(false,nil,nil,errors,nil) end render json: response end def update @content_increment.update_attributes(content_increment_params) if @content_increment.save response = Mks::Common::MethodResponse.new(true, 'Content increment updated successfully !',nil,nil,nil) render json: response else errors = Mks::Common::Util.error_messages(@content_increment, 'ContentIncrement') 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_content_increment @content_increment = SpecialIncrementContentRate.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def content_increment_params params.require(:content_increment).permit(:id, :content_type_id, :rate, :effective_date) end end end end