Forum: Ruby on Rails How Would I Display Today's Posts Only?

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.
2c2f3ce7125411ff78a1d3e902aa2a4d?d=identicon&s=25 Bob Sanders (adistarmid)
on 2007-06-17 12:23
I have a list of posts where I would simply like to display today's post
entries only. I thought about using if-then statements, but is there a
better way to do it?

(As you can tell, I'm an ignorant noob :)
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2007-06-17 12:45
(Received via mailing list)
On 17 Jun 2007, at 12:23, Bob Sanders wrote:

> I have a list of posts where I would simply like to display today's
> post
> entries only. I thought about using if-then statements, but is there a
> better way to do it?
>
> (As you can tell, I'm an ignorant noob :)


What about in your Post model:

def self.todays_posts
    self.find(:all, :conditions => ["post_date = ?", Date.today])
end


Then in your controller:

def index
    @posts = Post.todays_posts
end

And in your view:

<% @posts.each do |post| %>
...
<%= h post.title %>
...
<% end %>


Best regards

Peter De Berdt
2c2f3ce7125411ff78a1d3e902aa2a4d?d=identicon&s=25 Bob Sanders (adistarmid)
on 2007-06-18 02:11
Thanks, Peter!
This topic is locked and can not be replied to.