ruby-on-rails-3squeel

what default value of a date should be given that it returns all the record if user has not entered date in squeel


I am using a squeel gem and I have a scenario that when user does not enter employee joining date then all the records should be returned else return record on the basis of employees joining date. my query is loke this :

date = Date.today Employee.joins { passports.visas }.where { (employees.joining_date.eq "%#{date}%")

so if date is not given by the user then what should I put the default value of date so that it retrieve all the record?


Solution

  • simply make call back

    in Employee model before_create :joining_date

    def joining_date self.joining_date = Date.today end