Forum: Ruby on Rails Display list based on date

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae69a35a268082691bb320d3cfb366c3?d=identicon&s=25 Grant Blakeman (gblakeman)
on 2007-01-09 06:33
Hi, this is probably simple, but I'm just starting to learn...

I have an action that displays a paginated list of events in one table
of my database. I want it to display all of the events from today's date
and onward (exclude past events, basically). This is as far as I've
gotten:

def list
   @show_pages, @shows = paginate(:shows, :per_page => 15, :conditions
=> ['shows.date_time >= ?', '2007-01-08 22:01:00' ], :order => %w(
shows.date_time ))
end

Putting today's date/time in the database query is where I'm stuck. I
manually entered the date/time you see above and it works perfectly.

What do I need to do to include a dynamically generated date/time?

Thanks in advance!
Ae69a35a268082691bb320d3cfb366c3?d=identicon&s=25 Grant Blakeman (gblakeman)
on 2007-01-09 06:38
Grant Blakeman wrote:
> I have an action that displays a paginated list of events in one table
> of my database. I want it to display all of the events from today's date
> and onward (exclude past events, basically). This is as far as I've
> gotten:
>
> def list
>    @show_pages, @shows = paginate(:shows, :per_page => 15, :conditions
> => ['shows.date_time >= ?', '2007-01-08 22:01:00' ], :order => %w(
> shows.date_time ))
> end
>
> Putting today's date/time in the database query is where I'm stuck. I
> manually entered the date/time you see above and it works perfectly.

Nevermind, I figured it out - placing Time.now without quotes did the
trick - I think I had originally been trying Date.now and getting now
results because time wasn't included...

Here's the working code:

  def list
      @show_pages, @shows = paginate(:shows, :per_page => 15,
:conditions => ['shows.date_time >= ?', Time.now ], :order => %w(
shows.date_time ))
  end
This topic is locked and can not be replied to.