Class: Sivel2Gen::UbicacionesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sivel2_gen/ubicaciones_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



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

def nuevo
  if !params[:caso_id].nil?
    @ubicacion = Msip::Ubicacion.new
    @ubicacion.caso_id = params[:caso_id]
    @ubicacion.pais_id = Msip.paisomision
    if @ubicacion.save(validate: false)
      respond_to do |format|
        format.js { render text: @ubicacion.id.to_s }
        format.json { render json: @ubicacion.id.to_s, status: :created }
        format.html { render inline: @ubicacion.id.to_s }
      end
    else
      respond_to do |format|
        format.html { render action: "error" }
        format.json { render json: @ubicacion.errors, status: :unprocessable_entity }
      end
    end
  else
    respond_to do |format|
      format.html { render inline: 'Falta identificacion del caso' }
    end
  end
end

#ubicacion_paramsObject



48
49
50
51
52
53
54
# File 'app/controllers/sivel2_gen/ubicaciones_controller.rb', line 48

def ubicacion_params
  params.require(:ubicacion).permit(
    :id, :pais_id, :departamento_id, :municipio_id, :centropoblado_id, 
    :lugar, :sitio, :latitud, :longitud, :tsitio_id, 
    :_destroy
  )
end

#updateObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/sivel2_gen/ubicaciones_controller.rb', line 33

def update
  if @caso.update(ubicacion_params)
    respond_to do |format|
      format.js { render text: @ubicacion.id.to_s }
      format.json { render json: @ubicacion.id.to_s, status: :updated }
      format.html { render inline: @ubicacion.id.to_s }
    end
  else
    respond_to do |format|
      format.html { render action: "error" }
      format.json { render json: @ubicacion.errors, status: :unprocessable_entity }
    end
  end
end