我有以下关系建立在我的节日模型,类别,提交和策展人(用户)。
当管理员(用户)登录并查看提交的索引时。他们只应看到他们担任馆长的意见书(通过类别)。我很困惑如何生成合适的意见书列表。下面是控制器中的内容:
def index
@submissions = current_festival.submissions.all
end这将返回当前节日的所有提交,而不只是来自类别,current_user是策展人。我想要的是这样的东西,但我不知道正确的语法:
def index
@categories = current_user.categories.where(festival_id: current_festival.id)
@submissions = current_festival.submissions.where( category_id: "one of the @categories" )
end知道正确的语法是什么吗?
发布于 2013-10-30 21:58:04
这将为您提供属于current_user创建的类别的所有提交
def index
category_ids = current_user.categories.where(festival_id: current_festival.id).collect(&:id)
@submissions = current_festival.submissions.where(category_id: category_ids)
endhttps://stackoverflow.com/questions/19694214
复制相似问题