轨道中的IF条件未执行

时间:2013-04-20 07:49:24

标签: ruby-on-rails search solr

我正在尝试根据用户输入的文本进行solr搜索。我要检查输入的文本是商店,品牌还是类别。在检查该条件后,我想使用solr搜索显示MainNavigationUrls表中的相应结果。这是控制器动作。如果我进入任何商店并且可以获得适当的结果,它工作正常。但如果找到商店搜索,它就不会进入品牌循环。请解释为什么它没有执行第二种情况。

def search_all
    @storesearch=Site.search do
      fulltext params[:text]
      with(:multibrand,1)
    end

    if(@storesearch.nil?)
      @brandsearch=Brand.search do
        fulltext params[:text]
      end
      if(@brandssearch.nil?)
        @itemcategorysearch=MainCategory.search do
          fulltext params[:text]
        end
        @itemcategorysearch.results.each do |result|
          @itemcategorysearch1=MainNavigationUrl.search do
            with :main_categoty_id, result.id
            with :department_id, params[:deptid].to_i
            paginate :page=>params[:page], :per_page=>45
          end
        end
      else
        @brandsearch.results.each do |result|
          @brandsearch1=MainNavigationUrl.search do
            with :brand_id, result.id
            with :department_id, params[:deptid].to_i
            paginate :page=>params[:page], :per_page=>45  
          end
        end

    else
      @storesearch.results.each do |result|
        @storesearch1=MainNavigationUrl.search do
          with :site_id, result.id
          with :department_id, params[:deptid].to_i
          paginate :page=>params[:page], :per_page=>45
        end
      end
    end
  end

1 个答案:

答案 0 :(得分:0)

而不是.nil? ,也许你可以使用.blank?更好吗?

@array = []
@array.nil? -false
@array.blank?  -true

我认为你正在检查@storesearch是否包含一些元素?