0

コントローラ:

@sites = Site.inspections_enabled_controllers_search.search("test")

@sites.each do |s|
    if s == nil
        puts "WHAT THE ...?"
    end
    ap s #print out the site
end

モデル:

has_many :inspections_enabled_controllers, 
            :class_name => 'Controller', 
            :conditions => ['controllers.inspections_enabled = ?', true]

sphinx_scope(:inspections_enabled_controllers_search) {
    {
        :joins => :inspections_enabled_controllers
    }
}

戻り値:

#<Site:0x000000114618b8> {
              :id => 156,
            :name => "Test Site"
}
WHAT THE ...?
nil
WHAT THE ...?
nil
WHAT THE ...?
nil
#<Site:0x000000111c41a0> {
              :id => 213,
            :name => "TestRail V1.5 - SmartLine"
}
WHAT THE ...?
nil
WHAT THE ...?
nil
WHAT THE ...?
nil
WHAT THE ...?
nil
#<Site:0x00000011461200> {
              :id => 220,
            :name => "Activation Testing"
}

配列内の単に空のアイテムである合計 7 個の「-」に注意してください。

4

1 に答える 1

1

これは私のために働いた

@sites = Site.inspections_enabled_controllers_search.search("test", :retry_stale => 1)

参考: http: //pat.github.com/ts/en/searching.html#nils

于 2013-03-22T17:06:27.470 に答える