私は多くのコントローラーを持っている従業員モデルを持っています
jobs_controller.rb
contacts_controller.rb
personals_controller.rb
dependets_controller.rb
それらはすべて従業員コントローラーに関連しています。私はMongoDbを使用しています。これは、コントローラーが異なるため、モデルも異なるためです。ダッシュボードに、関連する従業員の詳細を表示する必要があります。ここで、1つのフィールドは連絡先コントローラーから、別のフィールドはdependents_controllerから、別のフィールドはパーソナルコントローラーからのものです。ここでは、すべてのモデルを呼び出し、各モデルから1つのフィールドをフェッチする必要があります。1つの関連するモデルの各フィールドを表示して、このコードをカスタマイズできますか?私はデバイスを使用しています。各ユーザー関連データのIDを保存して、ユーザーモデルを呼び出すことはできませんか?私はめちゃくちゃです..もしそうなら、どうやって?私の従業員コントローラーで
def index
@employees = Employee.all
Employee.includes(:dependants).each do |dependant|
p dependant.firstname #example of pulling data for that related entity
end
end
また、関係者データを見つけるにはどうすればよいですか?