在我的节日申请和意见书中我有模型。每件作品都属于一个节日。我有一个助手根据每个节日的日期来确定"current_festival“是什么。
module ApplicationHelper
def current_festival
@current_festival ||= Festival.current.first
end
end.current是节日模型中的一个范围:
scope :current, where("published = true and closing_date >= ?", Time.now.to_date).order('closing_date asc').limit(1)我想要的是限制在索引视图中显示的提交只属于当前的节日。在控制器里你会怎么做?还是最好在模型中这样做,也许是通过一个范围?
发布于 2013-10-29 23:03:44
我想你有这样定义的关系:
class Festival
has_many :submissions
end那么你可以在任何地方做:
Festival.current.submissionshttps://stackoverflow.com/questions/19670656
复制相似问题