检索 Rails 中的特定装置

发布于 2024-08-25 09:23:03 字数 374 浏览 4 评论 0原文

我有一个 YML 文件,其中包含 Rails 模型的固定装置(注释),如下所示(请原谅格式):

评论_a: 编号:1 文本:'foo' 可见:假

评论_b: 编号:2 文字:“酒吧” 可见:真实

评论_c: 编号:3 文字:“巴兹” 可见:真实

我知道我可以选择一个单独的评论装置,如下所示:

评论(:comment_a)

在我的一项验收测试中,我想找到所有具有visible = true的评论。如何选择一组满足特定条件的评论,以便之后可以迭代它们?

I have a YML file containing fixtures for a Rails model (Comment) which looks like this (pardon the formatting):

comment_a:
id: 1
text: 'foo'
visible: false

comment_b:
id: 2
text: 'bar'
visible: true

comment_c:
id: 3
text: 'baz'
visible: true

I know that I can select an individual Comment fixture like so:

comments(:comment_a)

In one of my acceptance tests, I want to find all the Comments which have visible = true. How do I select a set of Comments that meet certain criteria so I can iterate over them afterwards?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放肆 2024-09-01 09:23:03

您需要通过 ActiveRecord 对象发出请求。 Comments.all(:conditions => {:visible => true})

You need made the request by your ActiveRecord Object. Comments.all(:conditions => {:visible => true})

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文