Question

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'
Was it helpful?

Solution

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.

OTHER TIPS

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

STI

STI SAMPLE

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top