user1047912
user1047912

Reputation:

rails console get all

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.

Upvotes: 0

Views: 1864

Answers (4)

deyan
deyan

Reputation: 112

Account.where(zipcode: "XXXXX")

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

Upvotes: 1

Dave Isaacs
Dave Isaacs

Reputation: 4539

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

Upvotes: 1

Matthew Lehner
Matthew Lehner

Reputation: 4027

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

Upvotes: 0

MrDanA
MrDanA

Reputation: 11647

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

This returns an array of Account objects.

Upvotes: 1

Related Questions