我正在使用 rails 3,我似乎无法检查给定实例是否在范围内,请参见此处:
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 |
+----+----------+-------------------------+-------------------------+-------------------------+-----------+
我有一个menu
看起来像这样的范围:
scope :menu, where("published != ?", false).limit(4)
当我运行它时,我得到:
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 |
+----+------------------+------------------+------------------+-------------------+-----------+
这是正确的,但是如果我尝试使用以下方法检查是否p
在menu
范围内:Post.menu.exists?(p)
我得到true
了它应该在的时间false
找出某个给定实例是否在范围内的正确方法是什么?