Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

29 lines (24 sloc) 0.528 kb

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  
Jump to Line
Something went wrong with that request. Please try again.