简体   繁体   中英

Rails Model Setup Roles

I'm working on a rails 4 app and i have two models Developers and Apps. A developer can have many apps and belongs to many apps. (Multiple developers for an app) I have successfully setup a joining table and everything works but i want to extent this so that a developer is either a :founder where he can have access to edit the app or a collaborator who only has access to view the app. Any suggestions on the best possible was to achieve this functionality?

App

  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

Developer

  has_and_belongs_to_many :apps, foreign_key: 'collaborator_id'
  has_and_belongs_to_many :apps, foreign_key: 'founder_id'

I think you need create another table:

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

      t.timestamps
    end
  end

User and application will have many assess_restricts.

I would suggest to use single table inheritance in this case.

STI

STI SAMPLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM