我正在开发一个rails 4应用程序,我有两个模型开发人员和应用程序。开发人员可以拥有许多应用程序并且属于许多应用程序(一个应用程序的多个开发人员)我已成功设置加入表格,并且一切正常,但我想扩展此范围,以便开发人员可以是:创建者,他可以访问编辑应用程序或只能访问视图的协作者应用程序。任何关于尽可能好的建议都是为了实现这一功能?Rails模型设置角色
应用
has_and_belongs_to_many :collaborators, class_name: 'Developer', association_foreign_key: :collaborator_id
has_and_belongs_to_many :founders, class_name: 'Developer', association_foreign_key: :founder_id
开发
has_and_belongs_to_many :apps, foreign_key: 'collaborator_id'
has_and_belongs_to_many :apps, foreign_key: 'founder_id'
你怎么定义'通过的has_many through'或'has_and_belongs_to_many'上'App'和'Developer'关系? – j03w
@ j03w我更新了我的问题 – ny95
您有2个选择 1.创建一个类似于@zolter答案建议的新表,并且使用'has_many through'而不是'hbtm'在'edit'和'update'方法中有一些检查在你的控制器中。 2.修改你的'hbtm'成为一个合适的模型表:添加迁移创建时间戳列http://stackoverflow.com/questions/7542976/add-timestamps-to-an-existing-table并添加'角色'列到桌上也是如此。然后在'models'中创建'model'文件 – j03w