営業担当者向けのアプリケーションがあります。私は2つのことに基づいてさまざまな機関の情報を取得しようとしています
- 彼らがクライアントの場合
- ユーザー(営業担当者)が終了した状態の場合。
そこで、current_user(営業担当者)エリアのクライアントであるすべての機関を表示したいと思います。どうやってやるの?
私はこれまでこれを行ったことがなく、Railsに慣れていないため、これを行う方法がわかりません。
これが私のモデルです(コードを短縮しました):
ユーザー(営業担当者)
class User < ActiveRecord::Base
has_many :states, :through => :rep_areas
has_many :institutions, :through => :company_reps
has_many :rep_areas
has_many :company_reps
end
州
class State < ActiveRecord::Base
has_many :users, :through => :rep_areas
has_many :rep_areas
has_many :institutions
attr_accessible :code, :name
end
機関
class Institution < ActiveRecord::Base
attr_accessible :company, :phone, :clientdate, :street, :city, :state_id, :zip, :source, :source2, :demodate1, :demodate2, :demodate3, :client, :prospect, :notcontacted
belongs_to :state
has_many :users, :through => :company_reps
has_many :company_reps
end