【发布时间】:2014-01-23 11:59:46
【问题描述】:
我的数据库中有四个表。一个是用户,另一个是组织。一个用户可以拥有多个组织,一个组织可以拥有多个用户。此关系存储在名为 user_organizations 的第三个表中,其中包含 user_id 和 organization_id 列。
第四个表称为 organization_details,我在其中存储有关组织的其他多行信息。
我想要发生的是:当登录用户想要将组织详细信息添加到他们通过 user_organizations 链接到的组织时,只有他们链接到的组织应该出现在下拉列表中。
我不确定该怎么做。系统通过current_user返回登录用户的信息,例如。
所以我正在尝试做这样的事情:
collection_select(:organization_detail, :organization_id, Organization.where({id: current_user.id...关于 user_organization 也在这里}), :id, :name_and_state)
解决此问题的最佳方法是什么?非常感谢!
【问题讨论】:
标签: ruby-on-rails