如何创建路由及其相应的控制器方法,以根据属性过滤索引操作内容?
我当前的路线.rb有:
resources :parties
resources :organizations, controller: 'parties', type: 'Organization'
resources :people, controller: 'parties', type: 'Person'
当我只需要过滤客户方时,我会运行查询:
Party.joins(:party_relationships).where(party_relationships: {relation:"customer"})
如何创建路由让控制器知道我必须仅过滤客户方,同时保持我的路线RESTful?
提前致谢,
此致 Leandro的
有关当前型号的更多信息:
方
class Party < ActiveRecord::Base
has_many :party_relationships
has_many :second_parties, :through => :party_relationships
scope :organizations, -> { where(type: 'Organization') }
scope :people, -> { where(type: 'Person') }
def self.types
%w(Organization Person)
end
end
组织
class Organization < Party
end
人
class Person < Party
end
会员的关系
class PartyRelationship < ActiveRecord::Base
belongs_to :party, :class_name=>'Party'
belongs_to :second_party, :class_name => 'Party'
enum relation: [ :customer, :supplier, :employee ]
end