core/app/models/concerns/person.rb in gaku-0.0.3 vs core/app/models/concerns/person.rb in gaku-0.1.0
- old
+ new
@@ -1,16 +1,27 @@
module Person
extend ActiveSupport::Concern
included do
+
validates :name, :surname, presence: true
def to_s
"#{surname} #{name}"
end
def phonetic_reading
"#{surname_reading} #{name_reading}"
+ end
+
+ def age
+ Date.today.year - birth_date.year
+ end
+
+ ransacker :age do
+ Arel::Nodes::SqlLiteral.new(
+ "DATE_PART('year', AGE(NOW(), birth_date))"
+ )
end
end
end