简体   繁体   中英

checking events that are on tomorrow in rails?

HI

i would like to write a method that returns all the events that are on tomorrow or within the next 24 hours.

eg

def tomorrows_events
  @events = Event.will_occur_in next_24_hours
end

i have a datetime for each event which is called so to get it it would be, @event.date_and_time

i have the search logic gem installed but don't know if it supports dates, i couldn't find anything on it.

what would be the best way to write it? is there something in search logic i can use?

thanks

Event.all(:conditions => { :date_and_time => (Time.now.tomorrow.beginning_of_day)..Time.now.tomorrow.end_of_day})

I wrote a plugin that'll help you do this: http://github.com/radar/by_star .

You'd use this command for it:

Event.tomorrow(Time.zone.now, :field => "date_and_time")

Then it will return only results for tomorrow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM