Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在建立一个网站,显示每周将要发生的事情的简历。我的问题是:管理员可以在两个月后发布帖子,我如何才能限制这些帖子在实际发生的那一周出现?
使用一个或两个范围:
class Post < ActiveRecord::Base scope :future, lambda { where('ends_at > ?', Time.zone.now') } scope :up_to, lambda { |time| where('starts_at < ?', time) } end @coming_up_posts = Post.future.up_to(7.days.from_now)