catch species not found errors in search

This commit is contained in:
Emi Matchu 2010-11-18 23:25:34 -05:00
parent badc2e6b3c
commit 8b159c02bd
2 changed files with 13 additions and 3 deletions

View file

@ -321,12 +321,20 @@ class Item < ActiveRecord::Base
end
search_filter :only do |species_name|
id = Species.require_by_name(species_name).id
begin
id = Species.require_by_name(species_name).id
rescue Species::NotFound => e
raise SearchError, e.message
end
arel_table[:species_support_ids].eq(id.to_s)
end
search_filter :species do |species_name|
id = Species.require_by_name(species_name).id
begin
id = Species.require_by_name(species_name).id
rescue Species::NotFound => e
raise SearchError, e.message
end
ids = arel_table[:species_support_ids]
ids.eq('').or(ids.matches_any([
id,

View file

@ -3,7 +3,9 @@ class Species < PetAttribute
def self.require_by_name(name)
species = Species.find_by_name(name)
raise ArgumentError, "Species \"#{name.humanize}\" does not exist" unless species
raise NotFound, "Species \"#{name.humanize}\" does not exist" unless species
species
end
class NotFound < ArgumentError;end
end