1 if nsfw 2 @items = Item.all(:limit => 10, :order => [:created_at.desc]) 3 else 4 # this also excludes all items without any tag 5 items_without_nsfw = Item.all(:limit => 10, :order => [:created_at.desc], :tags => {:tagname.not => 'nsfw'}) 6 # we need to include them afterwards: 7 items_without_tags = Item.all(:limit => 10, :order => [:created_at.desc], :tags => nil) 8 @items = (items_without_nsfw + items_without_tags).all(:limit => 10, :order => [:created_at.desc]) 9 end