Skip to content

Commit

Permalink
Validación de número de hijos. Closes https://gitlab.com/pasosdeJesus…
Browse files Browse the repository at this point in the history
  • Loading branch information
vtamara committed Jun 18, 2023
1 parent 255c34d commit 1bf73fd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/models/sivel2_gen/caso.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

require 'sivel2_gen/concerns/models/caso'

module Sivel2Gen
class Caso < ActiveRecord::Base
include Sivel2Gen::Concerns::Models::Caso

has_many :victima, foreign_key: "caso_id", dependent: :destroy,
class_name: 'Sivel2Gen::Victima', validate: true
end
end
20 changes: 20 additions & 0 deletions app/models/sivel2_gen/victima.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

require 'sivel2_gen/concerns/models/victima'

module Sivel2Gen
class Victima < ActiveRecord::Base
include Sivel2Gen::Concerns::Models::Victima

validate :hijos_valido

def hijos_valido
debugger
if self.hijos && (self.hijos < 0 || self.hijos > 100)
errors.add(
:hijos, "El número de hijos debe estar en blanco o "\
"ser un número entre 0 y 100")
end
end

end
end

0 comments on commit 1bf73fd

Please sign in to comment.