Permalink
Browse files

added NOTES on how to setup alternative multi roles model using habtm

  • Loading branch information...
1 parent 336eb5d commit 23eb6d175f93a8657a7a8df7c3be3dd305846bee @kristianmandrup committed Jan 6, 2011
Showing with 30 additions and 1 deletion.
  1. +28 −0 NOTES.textile
  2. +2 −1 lib/generators/active_record/roles/roles_generator.rb
View
@@ -0,0 +1,28 @@
+h1. Alternative Multi Roles setup
+
+<pre>
+ 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
+</pre>
+
+And your models look like this:
+
+<pre>
+ # 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
+</pre>
@@ -34,7 +34,8 @@ def apply_role_strategy
return
end
- begin
+ begin
+ logger.debug "Trying to insert roles code into #{user_class}"
insert_into_model name do
insertion_text
end

0 comments on commit 23eb6d1

Please sign in to comment.