Rails 控制台获取全部
我有一个关于 Rails Console 的非常简单的问题,如果我想获得一个帐户,我会这样做: y Account.find_by_zipcode("XXXXX")
这只会返回一个帐户,如果我想获取所有具有该邮政编码的帐户该怎么办?多谢。
I have a very simple question about rails console, if I want to get a single account I do this:
y Account.find_by_zipcode("XXXXX")
This returns me only one account, what if I want to get all the accounts which have that zipcode. Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过
Account.find_all_by_zipcode('XXXXX')
?Have you tried
Account.find_all_by_zipcode('XXXXX')
?这将返回一个 Account 对象数组。
This returns an array of Account objects.
是要走的路。 “find_all”在 Rails 4 中已被弃用
is the way to go. "find_all" is depreciated in Rails 4
Account.where(:zipcode => 'XXXXX')
会给你你想要的。Account.where(:zipcode => 'XXXXX')
will give you what you want.