1

난 내 레일 응용 프로그램에서 전체 텍스트 검색을 구현하려고합니다. 신청서는 comfortable_mexican_sofa을 기준으로합니다. 전체 텍스트를 보려면 sunspot gem을 사용하고 있습니다. Pages 클래스에 검색 가능한 특성을 추가해야합니다. 같은 클래스의 모델에서 새 파일을 만들었지 만 작동하지 않는 것 같습니다. 이 수업을 어떻게 확장 할 수 있습니까? 나는 오류를 당신은이 일을 시도 할 수comfortable_mexican_matress에서 모델 확장

`undefined method `search' for #<Class:0x007fbe90f6faa8>` 

응용 프로그램/모델/Page.rb

class Comfy::Cms::Page < ActiveRecord::Base 
    searchable do 
    text :label, :content_cache 
    boolean :featured 
    end 
end 

articles_controller.rb

def index 
    since = params[:sinceDate] 
    query = params[:searchQuery] 
    @articles = nil 
    if query 
     @articles = Comfy::Cms::Page.search{ fulltext query }.published.all 
    else 
     @articles = Comfy::Cms::Page.published.all 
    end 
    if since 
     @articles = @articles.reject{ |a| a[:created_at] < Date.parse(since) } 
    end 
    # @articles 
    # if query 
    # @articles = @articles.select{ |a| a[:label].match(/#{query}/i) } 
    # end 
    end 

답변

2

점점 오전 :

파일을 확인하고 이니셜 라이저 폴더에 넣으십시오 :

Comfy::Cms::Page.class_eval do 
    searchable do 
    text :label, :content_cache 
    boolean :featured 
    end 
end