Rails模型设置角色

时间:2013-08-25 04:49:20

标签: ruby-on-rails activerecord ruby-on-rails-4 activemodel

我正在开发rails 4应用程序,我有两个模型开发人员和应用程序。开发人员可以拥有许多应用,并且属于许多应用。 (应用程序的多个开发人员)我已经成功设置了一个连接表,一切正常但我希望扩展这一点,以便开发人员是:创建者,他可以有权访问编辑应用程序或只有访问权限的协作者该应用程序。有关最佳可能性的任何建议都是为了实现这一功能吗?

应用

  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'

2 个答案:

答案 0 :(得分:1)

我认为你需要创建另一个表:

  def change
    create_table :access_restricts do |t|
      t.integer :user_id
      t.integer :application_id
      t.integer :role_id

      t.timestamps
    end
  end

用户和应用程序将有许多assessment_restricts。

答案 1 :(得分:0)

我建议在这种情况下使用单表继承。

STI

STI SAMPLE

相关问题