adds search to Booth model

This commit is contained in:
Juanjo Bazán
2016-12-23 19:03:39 +01:00
parent ae6bccd98f
commit 89979e549f
2 changed files with 16 additions and 0 deletions

View File

@@ -4,5 +4,10 @@ class Poll
has_many :polls, through: :booth_assignments
validates :name, presence: true, uniqueness: true
def self.search(terms)
return Booth.none if terms.blank?
Booth.where("name ILIKE ? OR location ILIKE ?", "%#{terms}%", "%#{terms}%")
end
end
end