Sha256: 4b1436a9c6def390c9440c0b501955ee40482e41784b17f54aee66b106d17774
Contents?: true
Size: 1.86 KB
Versions: 9
Compression:
Stored size: 1.86 KB
Contents
module Logistics module Core class AgentsController < ApplicationController before_action :set_agent, only: [:update] def index @agents = Logistics::Core::Agent.all agents_array =[] @agents.each { |agent| agents_array.push({:id => agent.id, :name => agent.name, :email => agent.email, :contact_telephone => agent.contact_telephone }) } @response = Mks::Common::MethodResponse.new(true, nil, agents_array, nil, nil) render json: @response end def create @agent = Logistics::Core::Agent.new(agent_params) if @agent.valid? @agent.save @response = Mks::Common::MethodResponse.new(true, 'Agent saved successfully !',nil,nil,nil); render json: @response else errors = Mks::Common::Util.error_messages @agent, 'Agent' @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) render json: @response end end def update if @agent.update_attributes(agent_params) @agent.save @response = Mks::Common::MethodResponse.new(true, 'Agent updated successfully !', nil, nil, nil) render json: @response else errors = Mks::Common::Util.error_messages @agent, 'Agent' @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_agent @agent = Logistics::Core::Agent.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def agent_params params.require(:agent).permit(:name, :email, :contact_telephone) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems