Andrey Drozdov Andrey Drozdov - 1 month ago 4x
Ruby Question

Select from DB without some value

I have my own rails app and I need to specify what I want to get from DB (pg). Ordinary, we do it like that:

@posts = Post.all
and I will get all the post in my Post Table.

In Post Table I have a categories, as a boolean: (photo, video, etc.) and when I want to select only posts witch response to photo category, we do it like that:
@posts = Post.where(photo: true)

But what I need, is to select all posts without, for example, video. It have to look something like that:
@posts = Post.all.without(video:true)
. How to make it happen?


you can use .not, for example

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