2019-04-05 22:40:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Las posiciones solo se pueden agregar a su consenso
|
|
|
|
class PosicionesController < ApplicationController
|
2019-04-06 19:45:07 +00:00
|
|
|
before_action :authenticate!
|
|
|
|
|
2019-04-05 22:40:28 +00:00
|
|
|
def create
|
|
|
|
@consenso = Consenso.find(params[:consenso_id])
|
2019-04-06 19:45:07 +00:00
|
|
|
@posicion = @consenso.try(:posiciones).try(:build, posicion_params)
|
|
|
|
@posicion.try(:pirata=, current_pirata)
|
2019-04-05 22:40:28 +00:00
|
|
|
|
2019-04-06 19:45:07 +00:00
|
|
|
if @posicion.try(:save)
|
|
|
|
render status: :created
|
|
|
|
else
|
|
|
|
render json: @posicion.try(:errors).try(:full_messages),
|
|
|
|
status: :unprocessable_entity
|
|
|
|
end
|
2019-04-05 22:40:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def posicion_params
|
|
|
|
params.require(:posicion).permit(:estado, :comentario)
|
|
|
|
end
|
|
|
|
end
|