I created an helper in my application_helper:
def birthday(geburt)
f = Date.today
a = f.year - geburt.year
a = a - 1 if (
geburt.month > f.month or
(geburt.month >= f.month and geburt.day > f.day)
)
a
end
Now i try tu use this helper in an model:
patients = patients.where("birthday(geburtsdatum) >= ?", minimum) if minimum.present?
But how you can see in the error i somehow dont use my helper right. "geburtsdatum" is an colomn in my patients model. Thanks Error:
SQLite3::SQLException: no such function: birthday: SELECT "patients".* FROM "patients" WHERE (birthday(geburtsdatum) >= 15) ORDER BY vorname
My new code:
def find_patients
patients = Patient.order(:vorname)
patients = patients.where("nachname like ?", "%#{keyword}%") if keyword.present?
patients = patients.where("#{geburtsdatum.get_birthday} >= ?", minimum) if minimum.present?
patients
end
My new error:
undefined local variable or method `geburtsdatum' for #<Search:0x4ee51b8>