У меня есть следующая модель:
class Article < ActiveRecord::Base
define_index do
indexes content
indexes :name, sortable: true
has type
end
end
и специальный тип статьи:
class About < Article
end
и то же самое для Contact
Я хотел бы иметь доступное для поиска действие индексирования статей без статей с типом «О программе» или «Контакты».
class ArticlesController < ApplicationController
load_and_authorize_resource
def index
@articles = Article.search(params[:search],
:with_all => {:type => nil},
:page => params[:page],
:per_page => 10)
end
end
Но переменная экземпляра @articles
каждый раз содержит также статьи «О программе» и «Контакты».
Это очень странно (кажется, что will_paginate все портит):
@articles = Article.search(
:without => {:type => %w(About Contact)}).include?(About.first) # false
@articles = Article.search(
:without => {:type => %w(About Contact)},
:page => 1,
:per_page => 1000).include?(About.first) # true
=============================================================================
Наконец я сделал:
class Article < ActiveRecord::Base
define_index do
indexes content
indexes :name, sortable: true
has "CRC32(type)", :as => :article_type, :type => :integer
end
end
а также:
class ArticlesController < ApplicationController
load_and_authorize_resource
def index
@articles = Article.search(params[:search],
:without => {:article_type => ["About".to_crc32, "Contact".to_crc32]},
:page => params[:page],
:per_page => 10)
end
end
и это работает. Спасибо, парни!