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.

有帮助吗?

解决方案

Have you tried Account.find_all_by_zipcode('XXXXX')?

其他提示

Account.where(:zipcode => "XXXXX")

This returns an array of Account objects.

Account.where(zipcode: "XXXXX")

is the way to go. "find_all" is depreciated in Rails 4

Account.where(:zipcode => 'XXXXX') will give you what you want.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top