views:

46

answers:

1

I'm using rails 3 and I can't seem to check if a given instance is in a scope, see here:

p = Post.find 6
+----+----------+-------------------------+-------------------------+-------------------------+-----------+
| id | title    | publish_date            | created_at              | updated_at              | published |
+----+----------+-------------------------+-------------------------+-------------------------+-----------+
| 6  | asfdfdsa | 2010-03-28 22:33:00 UTC | 2010-03-28 22:33:46 UTC | 2010-03-28 22:33:46 UTC | true      |
+----+----------+-------------------------+-------------------------+-------------------------+-----------+

I have a menu scope which looks like:

scope :menu, where("published != ?", false).limit(4)

When I run it I get:

Post.menu.all
+----+------------------+------------------+------------------+-------------------+-----------+
| id | title            | publish_date     | created_at       | updated_at        | published |
+----+------------------+------------------+------------------+-------------------+-----------+
| 1  | Lorem ipsum      | 2010-03-23 07... | 2010-03-23 07... | 2010-03-28 21:... | true      |
| 2  | fdasf            | 2010-03-28 21... | 2010-03-28 21... | 2010-03-28 21:... | true      |
| 3  |  Ruby’s Imple... | 2010-03-28 21... | 2010-03-28 21... | 2010-03-28 21:... | true      |
| 4  | dsaD             | 2010-03-28 22... | 2010-03-28 22... | 2010-03-28 22:... | true      |
+----+------------------+------------------+------------------+-------------------+-----------+

Which is correct, but if I try to check if p is in the the menu scope using: Post.menu.exists?(p) I get true when it should be false

What is the proper way to find out if a given instance of something is in a scope?

A: 

Actually, I was able to solve it using that Array method of include? instead of exists?

Joseph Silvashy