Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从数据库中选择,但不选择某些值_Ruby On Rails_Ruby_Database_Postgresql - Fatal编程技术网

Ruby on rails 从数据库中选择,但不选择某些值

Ruby on rails 从数据库中选择,但不选择某些值,ruby-on-rails,ruby,database,postgresql,Ruby On Rails,Ruby,Database,Postgresql,我有我自己的rails应用程序,我需要指定我想从DB(pg)获得什么。一般来说,我们是这样做的:@posts=Post.all,我将获得我的Post表中的所有Post 在Post表中,我有一个类别,作为布尔值:(照片、视频等),当我只想选择对照片类别做出响应的帖子时,我们这样做:@posts=Post.where(照片:true) 但我需要的是选择所有没有视频的帖子。它必须看起来像这样:@posts=Post.all.without(video:true)。如何做到这一点 更新 是否有可能阻止几

我有我自己的rails应用程序,我需要指定我想从DB(pg)获得什么。一般来说,我们是这样做的:
@posts=Post.all
,我将获得我的Post表中的所有Post

在Post表中,我有一个类别,作为布尔值:(照片、视频等),当我只想选择对照片类别做出响应的帖子时,我们这样做:
@posts=Post.where(照片:true)

但我需要的是选择所有没有视频的帖子。它必须看起来像这样:
@posts=Post.all.without(video:true)
。如何做到这一点

更新

是否有可能阻止几个值?我的意思是类似于Post.where.not(id:1&&2)。我真的不知道它看起来是什么样子。我需要的是选择所有没有ID为1和2的帖子

试试看

@posts = Post.where.not(video: true)

例如,你可以使用

@posts = Post.where.not(video:true)

您可以传递一个值数组:
Post.where.not(id:[1,2])

或@posts=Post.where(视频:false)