Tran duy Khoa
Tran duy Khoa

Reputation: 59

AND OR filter in Ruby on rails

I have a question: how do i write 2 conditions in filters params? :page_path.eql => "/teams/1" or :page_path.eql => 'teams/2'

it works for one condition, but dont work with two:(

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

Upvotes: 1

Views: 277

Answers (1)

Pritesh Jain
Pritesh Jain

Reputation: 9146

Try this

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

you can also try shorthand

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

with date options

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

or

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

This works for me

use contains instead of matches I think it does not understand regex.

Upvotes: 0

Related Questions