How Would I Display Today's Posts Only?


#1

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 :slight_smile:


#2

On 17 Jun 2007, at 12:23, Bob S. 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 :slight_smile:

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


#3

Thanks, Peter!