Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 轨道4,Lupa:与或链接_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 轨道4,Lupa:与或链接

Ruby on rails 4 轨道4,Lupa:与或链接,ruby-on-rails-4,Ruby On Rails 4,我使用的过滤Lupa是独立于框架的,易于测试,基准测试可以很好地针对has_范围,等等 如何在Lupa中使用或逻辑链接作用域?当参数提前知道时效果很好,但当过滤器由用户决定时效果就不好了 也许解决方案在文档的日期间隔部分,但我似乎无法理解 我有一个表单,允许用户使用复选框选择动物的性别-雄性和雌性。我希望用户能够检查其中一个、另一个或两者,并返回直观的结果 @edelpero将我推向了正确的方向,但我觉得要么我误解了什么,要么文档可能会有所改进,可能是前者。当我从一个应用程序中简化时,下面可能会

我使用的过滤Lupa是独立于框架的,易于测试,基准测试可以很好地针对has_范围,等等

如何在Lupa中使用或逻辑链接作用域?当参数提前知道时效果很好,但当过滤器由用户决定时效果就不好了

也许解决方案在文档的日期间隔部分,但我似乎无法理解

我有一个表单,允许用户使用复选框选择动物的性别-雄性和雌性。我希望用户能够检查其中一个、另一个或两者,并返回直观的结果

@edelpero将我推向了正确的方向,但我觉得要么我误解了什么,要么文档可能会有所改进,可能是前者。当我从一个应用程序中简化时,下面可能会出现一些o型问题,但这里有一个解决方案:

形式

控制器

class PupsController < ApplicationController

def index
  @pups = PupSearch.new(Pup.all).search(search_params)
end

protected
    def search_params
      params.permit(:male, :female, :gender) # permit all three 
    end

end
范围类

class WalkSearch < Lupa::Search

  class Scope
    def male
      # leave blank to avoid chaining; handled in gender below
    end

    def female
      # leave blank to avoid chaining; handled in gender below
    end

    def gender
      # standard procedure for OR logic
      scope.joins(:pup).where('pups.male_female' => [
        search_attributes[:male],
        search_attributes[:female]
      ])
    end
  end

end
class WalkSearch < Lupa::Search

  class Scope
    def male
      # leave blank to avoid chaining; handled in gender below
    end

    def female
      # leave blank to avoid chaining; handled in gender below
    end

    def gender
      # standard procedure for OR logic
      scope.joins(:pup).where('pups.male_female' => [
        search_attributes[:male],
        search_attributes[:female]
      ])
    end
  end

end