Class: Logistics::Core::CarrierAgentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/carrier_agents_controller.rb

Instance Method Summary collapse

Instance Method Details

#carrier_agent_paramsObject



30
31
32
# File 'app/controllers/logistics/core/carrier_agents_controller.rb', line 30

def carrier_agent_params
  params.permit(:carrier_agents => [:carrier_id, :agent_id])
end

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/logistics/core/carrier_agents_controller.rb', line 15

def create
  carriers = params[:carrier_agents]
  if carriers.count > 0
    carrier = Carrier.find carriers[0][:carrier_id]
  end
  carriers.each do |c|
    agent = Agent.find c[:agent_id]
    carrier.agents << agent
  end

  carrier.save
  response = Mks::Common::MethodResponse.new(true, 'Agent(s) associated successfully !')
  render json: response
end

#indexObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/logistics/core/carrier_agents_controller.rb', line 5

def index
  @carrierAgents = CarrierAgent.all
  carrier_agent_array = []
  @carrierAgents.each { |ca|
    carrier_agent_array.push({ :id => ca.id, :name => ca.carrier.name+' '+ca.agent.name})
  }
  @response = Mks::Common::MethodResponse.new(true, nil, carrier_agent_array, nil, nil)
  render json: @response
end