내 경로 파일의 절반 이상이 제약 조건 (및 해당 클래스)과 함께 처리되므로 더 좋은 방법이 있는지 궁금합니다. 다른 애완 동물을 추가하면 각각의 애완 동물은 동일하므로 파일이 매우 길어질 수 있습니다.Rails 경로에서 이러한 제약 조건을 수행하는 더 좋은 방법이 있습니까?
class AkcConstraint
TYPES = %w[sporting-group hound-group working-group terrier-group toy-group non-sporting-group herding-group misc-class]
def self.matches?(request)
TYPES.include? request.path_parameters[:akc_group]
end
end
class AnkcConstraint
TYPES = %w[toy-group terrier-group gundog-group hound-group working-group utility-group non-sporting-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:ankc_group]
end
end
class CkcConstraint
TYPES = %w[sporting-group hound-group working-group terrier-group toy-group non-sporting-group herding-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:ckc_group]
end
end
class FciConstraint
TYPES = %w[group-1 group-2 group-3 group-4 group-5 group-6 group-7 group-8 group-9 group-10]
def self.matches?(request)
TYPES.include? request.path_parameters[:fci_group]
end
end
class IkcConstraint
TYPES = %w[group-1 group-2 group-3 group-4 group-5 group-6 group-7 group-8 group-9 group-10]
def self.matches?(request)
TYPES.include? request.path_parameters[:ikc_group]
end
end
class KcConstraint
TYPES = %w[hound-group working-group gundog-group terrier-group utility-group pastoral-group toy-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:kc_group]
end
end
class KusaConstraint
TYPES = %w[hound-group working-group gundog-group terrier-group utility-group pastoral-group toy-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:kusa_group]
end
end
class NzkcConstraint
TYPES = %w[toy-group terrier-group gundog-group hound-group working-group utility-group non-sporting-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:nzkc_group]
end
end
# For dog groups and types
match 'dogs/akc/:akc_group', :to => "dogs#index", :as => "akc_dogs",
:constraints => AkcConstraint
match 'dogs/ankc/:ankc_group', :to => "dogs#index", :as => "ankc_dogs",
:constraints => AnkcConstraint
match 'dogs/ckc/:ckc_group', :to => "dogs#index", :as => "ckc_dogs",
:constraints => CkcConstraint
match 'dogs/fci/:fci_group', :to => "dogs#index", :as => "fci_dogs",
:constraints => FciConstraint
match 'dogs/ikc/:ikc_group', :to => "dogs#index", :as => "ikc_dogs",
:constraints => IkcConstraint
match 'dogs/kc/:kc_group', :to => "dogs#index", :as => "kc_dogs",
:constraints => KcConstraint
match 'dogs/kusa/:kusa_group', :to => "dogs#index", :as => "kusa_dogs",
:constraints => KusaConstraint
match 'dogs/nzkc/:nzkc_group', :to => "dogs#index", :as => "nzkc_dogs",
:constraints => NzkcConstraint
나는 무엇보다 성능에 대해 우려하고 있습니다. 걱정해야합니까? 더 좋은 방법이 있습니까? 등 Akc
, Ankc
, Ckc
모든 가정
경로를 통해 슬러그를 구현하려는 것 같습니다. 아마도 [friendly_id] (https://github.com/norman/friendly_id) 등을 볼 수 있습니다. –
안녕하세요 앤드류, 그들은 개 모델의 AR 모델, 필드 및 값만입니다. 나는 '레지스트리'모델을 만드는 것을 고려해 봤지만 가능하다면 피하고 싶었던 URL (dogs/registry/akc/working-dogs 등)에 또 다른 요소를 도입 할 것입니다. – A4J