http://stackoverflow.com/questions/4307411/how-to-express-a-not-in-query-with-activerecord-rails
I'm using this: Topic.where('id NOT IN (?)',actions) Where actions is an array with: [1,2,3,4,5] Edit: For Rails 4 notation: Article.where.not(title: ['Rails 3', 'Rails 5'])
需求是 v1.2以前版本(v1.2不用过滤)的接口中过滤掉“电影、电视剧、动漫、综艺”以外的频道
两种方法都是好用的
if params[:version] < "1.2" arr = ["电影","电视剧","综艺","动漫"] #default_navi_channels = CmsChannel.where(title: arr).where('state = 1 and channel_type = ?' ,'cibn_navi_channel').order('position asc') default_navi_channels = CmsChannel.where('title IN (?)', arr).where('state = 1 and channel_type = ?' ,'cibn_navi_channel').order('position end