Skip to content

Instantly share code, notes, and snippets.

@rubymerchant
Created April 2, 2009 19:23
Show Gist options
  • Save rubymerchant/89372 to your computer and use it in GitHub Desktop.
Save rubymerchant/89372 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
named_scope :published, :conditions => ["posts.published_at <= ? AND posts.published_at IS NOT NULL", Date.today.to_s(:db)],
:order => 'published_at DESC, id DESC'
end
# When I do Post.published from console on staging and production then published_at is compared with "2009-04-02",
# which is correct as today's date is "2009-04-02" on staging/production systems as well as GMT.
# However when above named_scope gets invoked as part of a request to PostsController, published_at is compared
# with "2009-04-01". now why is the date not "2009-04-02"?? here is the message from log.
#SELECT * FROM `posts` WHERE (posts.published_at <= '2009-04-01' AND posts.published_at IS NOT NULL) ORDER BY published_at DESC, id DESC LIMIT 0, 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment