two forms do not update me, ruby on rails

0

I have a problem I have two forms in the first one saves some fields and then in the second it saves others when I'm going to update the id I get an error.

the second form the field is: attention.  thanks

     def update
       respond_to do |format|
        if @reunion.update(reunion_params)
             format.html { redirect_to @reunion, notice: 'Reunion was successfully updated.' }
             format.json { render :show, status: :ok, location: @reunion }
        else
          @negocios = Negocio.all
             format.html { render :edit }
             format.json { render json: @reunion.errors, status: :unprocessable_entity }
        end

     end
   end


    private

   def set_reunion
       @reunion = Reunion.find(params[:id])
   end



   def reunion_params
     params.require(:reunion).permit( :observacion, :subtotal,
     :planta_id, :ubicacion,:hora_entre,:nombre,:atencion,
     :producto_id,:cantidad,:valor,:reunionvalor_id)
   end

reunion.erb

model

  class Reunion < ApplicationRecord
  self.table_name = 'reuniones'
  belongs_to :planta
  belongs_to :centro_costo
  belongs_to :producto

  self.table_name = 'reuniones' 


  before_validation :asignar_valores_por_defecto_reunion


   def asignar_valores_por_defecto_reunion
    Time.zone = "America/Bogota"
    self.hora_pedido = Time.zone.now.strftime("%Y-%m-%d-%H:%M:%S" )
  end


  #Autocomplete

   def centro_costo_fullname
     centro_costo.fullname if centro_costo
   end

   def centro_costo_fullname=(fullname)
      self.centro_costo = CentroCosto.find_by_fullname(fullname) unless fullname.blank?
   end

   before_save :guardarreunion


   def guardarreunion
    self.reunionfullnombre  =self.nombre+" "+self.fecha_pedido.to_s+" "+self.fecha_entrega.to_s+" "+
self.ubicacion+" "+CentroCosto.where("id=?",self.centro_costo).last.fullname+" "+Planta.where("id=?",self.planta).last.plantafullnombre
   end


 # validaciones

   validates_presence_of :centro_costo_fullname
   validates  :ubicacion, presence: true, length: {minimum: 4, maximum: 50}
   validates  :nombre, presence: true, length: {minimum: 4, maximum: 50} 

   #El metodo que asigna los valores
    validate :asignar_valores_por_defecto_reunion
    def asignar_valores_por_defecto_reunion
      Time.zone = "America/Bogota"
      self.fecha_pedido = Time.zone.now.strftime("%Y-%m-%d")
      self.hora_pedido = Time.zone.now.strftime("%Y-%m-%d-%H:%M:%S" )
    end

validate :validar_horas  
#valida las horas. 
def validar_horas
  #Hora medotodo  cual es mayor  que otro
   if  hora_inicio < hora_final

   else
    errors.add(:hora_final,"La hora final de la reunion debe
    ser mayor a la de hora inicial")
   end
   #Condicion que tiene que ser mayor  a 4 horas

    if ( hora_final - ( 60 * 60 * 4 ) ) <= ( hora_inicio )

       validates_presence_of :observacion ,:message => 'La hora final debe ser mayor a 4 hora,
      Explicar por que No cumple 
      las politicas del Negocio, y el campo sera deshabilitado,'


    end


 end  

 #validate :prueba

 def prueba
  self.hora_pedido = Time.zone.now.strftime("%Y-%m-%d-%H:%M:%S" )
  if ( fecha_entrega - ( 60 * 60 * 24 ) ) <= ( hora_pedido )

   validates_presence_of :observacion ,:message => 'error 24,  '
  end
 end

validate :fecha_permitida
def fecha_permitida
  if self.fecha_entrega
    Time.zone = "America/Bogota"
    if self.fecha_entrega < Time.zone.now
      p self.fecha_entrega
     errors.add(:fecha_entrega, "Fecha y hora de entrega
    No puede ser de diás,hora o minutos anteriores de la hora actual")
    end
  end
end

end

    
asked by juan gomez 02.10.2017 в 17:33
source

0 answers