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"
}

注意总共有七个“-”,它们只是数组中的空项。

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 回答