Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 528 Bytes

NOTES.textile

File metadata and controls

28 lines (24 loc) · 528 Bytes

Alternative Multi Roles setup

  class UsersHaveAndBelongToManyRoles < ActiveRecord::Migration
    def self.up
      create_table :roles_users, :id => false do |t|
        t.references :role, :user
      end
    end

    def self.down
      drop_table :roles_users
    end
  end  

And your models look like this:

  # User Model
  class User < ActiveRecord::Base
    has_and_belongs_to_many :roles
  ....
  # Role model
  class Role < ActiveRecord::Base
    has_and_belongs_to_many :users
  end