AND OR在Ruby on rails上过滤

时间:2012-08-15 08:58:56

标签: ruby-on-rails ruby ruby-on-rails-3 garb-gem

我有一个问题:如何在滤波器参数中写出2个条件? :page_path.eql => "/teams/1" or :page_path.eql => 'teams/2'

它适用于一种情况,但不适用于两种情况:(

output = Exits.results(profile, :filters => {:page_path.eql => "/teams/1"})

1 个答案:

答案 0 :(得分:0)

试试这个

output = Exits.results(profile,:filters =>{:page_path.contains => "^/teams/[1|2]$"})

您也可以尝试速记

output = profile.exits(:filters =>{:page_path.contains => "^/teams/[1|2]$"})

包含日期选项

output = Exits.results(profile, :filters => {:page_path.contains => "^/teams/[1|2]$"},:start_date => Date.new(2012,8,13),:end_date => Date.today)

output = profile.exits(:filters => {:page_path.contains => "^/teams/[1|2]$"},:start_date => Date.new(2012,8,13),:end_date => Date.today)

这对我有用

使用contains代替matches我认为它不了解正则表达式。