Topic: Displaying an event for today

Hi all,

Here's what I'm trying to do.  I work at a university who needs to display who their resident director on duty is, and have it dynamically update whenever the date changes based on a table.  Here's what I'm working with currently.

Controller has:
def index
    @current_rd = Rdod.today
end

Model has:

  def self.today
    find(:all, :conditions => ['date = ?', Date.today])
  end

View (index.rhtml) has:
Hi, it's <%= @date.to_s(:long) %>.

<% for rdod in @current_rd -%>
Today's RD is <%= rdod.name %><br />
<%= rdod.date %><br /><% end %>

I added the display of the date just so I could make sure, but I plan on removing it from the view once it works.  As of right now, this script displays only the current time at the top of the page, and no records even though I've entered one in for today and tommorow.  Help?  Thanks!

Last edited by kindablue (2007-01-15 10:17:31)

Re: Displaying an event for today

Is the date column of type "datetime"? It might not be matching since the time isn't specified. You can try something like this:

def self.today
  find(:all, :conditions => ['date >= ? AND date < ?', Date.today, Date.today+1])
end

Untested.

Railscasts - Free Ruby on Rails Screencasts

Re: Displaying an event for today

Thanks a bunch!  That was the right answer!