如何通过一种资源为另一种资源编写named_scope?
我有一个属于
锻炼的群组资源。锻炼可以是公开的或私人的,并由锻炼表中的 share
列指定(该列是一个整数,如果锻炼是公开的,则包含 1)。
我正在尝试致电所有与公共锻炼相关的团体。我认为这需要通过 named_scope
完成,但我不确定语法。
在 groups_controller 中,我假设我会调用:
@groups = Group.public_groups.all
How should I write the named_scope
in Group.rb? (我在 Rails 2.3.8 中)
named_scope :public_groups, ...
I have a groups resource that belongs_to
Workouts. Workouts can be public or private and are designated as such by the column share
in the workout table (which is an integer and contains a 1 if the workout is public).
I am trying call all groups that are associated with public workouts. I assume this needs to be done through a named_scope
but I am unsure of the syntax.
In the groups_controller I am assuming I would call:
@groups = Group.public_groups.all
How should I write the named_scope
in Group.rb? (I'm in rails 2.3.8)
named_scope :public_groups, ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法:
Here's one way to do it: