0

I'm using squeel, and I have a search method in my Event.rb model, which receives a parameter(string) from a text_field input

def self.search(search)
  if search
    self.where{date.month.strftime("%B").matches("%#{search}%")}
  else
    find(:all)
  end
end

What I'm trying to accomplish is, if the user enters "fe" or "ap" search in the Event.date.month for a match ("february", "april", etc). At the moment is working only entering the month number 02, 04, etc.

I'd appreciate any help

Daniel Romero
  • 1,581
  • 1
  • 20
  • 33

1 Answers1

0

One approach could be to use the Chronic gem to parse the input date and use that to get all events on that date.

A side note: The find(:all) is deprecated, you could use self.all instead, or even better self.scoped so you can chain more scopes later

Jakob W
  • 3,347
  • 19
  • 27
  • I've tried chronic gem as you said, but is not exactly what I want, I don't want all the events on a date, I want, if for example the user enters mo, I want all the events that are on monday, awesome gem anyway I didn't know about it, thanks – Daniel Romero Feb 11 '13 at 21:34
  • Ok, will try to think of another way if I find some time. Hope you find another solution otherwise =) – Jakob W Feb 11 '13 at 21:40