diff --git a/lib/generators/rolify/templates/role-active_record.rb b/lib/generators/rolify/templates/role-active_record.rb index 02ee848d..8918b018 100644 --- a/lib/generators/rolify/templates/role-active_record.rb +++ b/lib/generators/rolify/templates/role-active_record.rb @@ -5,7 +5,7 @@ def self.table_name_prefix end <% end %> has_and_belongs_to_many :<%= user_cname.tableize %>, :join_table => :<%= "#{table_name(user_cname, true)}_#{table_name(role_cname, true)}" %> - belongs_to :resource, :polymorphic => true - + belongs_to :resource, :polymorphic => true, :optional => true + scopify end diff --git a/lib/generators/rolify/templates/role-mongoid.rb b/lib/generators/rolify/templates/role-mongoid.rb index 432a3c8b..12c417fb 100644 --- a/lib/generators/rolify/templates/role-mongoid.rb +++ b/lib/generators/rolify/templates/role-mongoid.rb @@ -2,8 +2,8 @@ class <%= role_cname.camelize %> include Mongoid::Document has_and_belongs_to_many :<%= user_cname.tableize %> - belongs_to :resource, :polymorphic => true - + belongs_to :resource, :polymorphic => true, :optional => true + field :name, :type => String index({