I am trying to retrieve all “cards” from Mongoid that have request=”preview”
I’m doing this via:
@preview_cards = Card.where("request" => "PREVIEW")
I have a few questions.
1) Why can’t I do?
@preview_cards = Card.find_by_request("PREVIEW")
I get an error: undefined method `find_by_request’ for Card:Class
2) Once I have the cards in the @preview_cards variable, I can’t iterate through them. For example:
@preview_cards.each do |c| c.fullname end
simply just returns the object id #<Mongoid::Criteria:0x103eaf778>
3) Is there an “all” method you can call instead of first and last. For example, this works:
@preview_cards.first.fullname
but i want to be able to iterate through each “row” in mongo.
Any help would be greatly appreciated! Thanks.
No schema, so no automagic method generation. You can create your own helpers, though.
Are you sure? That works fine for me. What’s returned is different than what happens once you try iterating. For example:
For getting all, use
all: