Reputation: 759
In my RoR application, I use Role Model and CanCan gems. There is no default role for users. Before I assign roles to a user, role_mask is empty. I can assign multiple roles. But I cannot remove all the roles and make roles_mask to nil again. The last role assigned will still exists I need to remove previously assigned roles, ALL of them!! is it possible??
Upvotes: 0
Views: 566
Reputation: 86
If you want to make a single user roles to nil then in your role modify action do like
user.roles_mask = nil
and save
if you want to make all the roles mask nil then you can do this by writing a rake task. something like
task :make_roles_nil => :environment do
User.all.each do |user|
user.roles_mask = nil
user.save
end
end
Put it into lib/tasks directory a file named user.rake and then run
bundle exec rake user:make_roles_nil RAILS_ENV = YOUR ENVIRONMENT(development or production)
Upvotes: 3