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