forked from OpenNeo/impress
catch species not found errors in search
This commit is contained in:
parent
badc2e6b3c
commit
8b159c02bd
2 changed files with 13 additions and 3 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue