Class: Sivel2Gen::CombatientesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sivel2_gen/combatientes_controller.rb

Instance Method Summary collapse

Instance Method Details

#nuevoObject

Crea un nuevo registro para el caso que recibe por parametro params. Pone valores simples en los campos requeridos



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/sivel2_gen/combatientes_controller.rb', line 8

def nuevo
  if params[:caso_id]
    @combatiente = Combatiente.new
    @combatiente.nombre = 'N'
    @combatiente.sexo = Msip::Persona.convencion_sexo[:sexo_masculino].to_s
    @combatiente.resagresion_id = 1
    @combatiente.caso_id = params[:caso_id]
    if @combatiente.save
      respond_to do |format|
        format.js { render json: {'combatiente' => @combatiente.id.to_s } }
        format.json { render json: {'combatiente' => @combatiente.id.to_s },
                                    status: :created } 
        format.html { render json: {'combatiente' => @combatiente.id.to_s } }
      end
    else
      respond_to do |format|
        format.html { 
          render inline: 'Error: ' + @combatiente.errors.messages.to_s 
        }
        format.json { render json: @combatiente.errors.messages, 
                      status: :unprocessable_entity }
      end
    end
  else
    respond_to do |format|
      format.html { render inline: 'Falta identificacion del caso' }
    end
  end
end