Two different user groups from database with devise and rolify

183 Views Asked by At

I'm using Devise and Rolify gem.

How to add a role to different user groups after registration? In my database I have "group" field which contains e.g. foo and bar strings. For foo I would like to add :foo role and for bar - :bar role.

I would like to do something like this: (in models/user.rb)

enter code here
class User < ActiveRecord::Base
rolify :after_create => :method

def method(role)
 if User.group=="foo"
  user.add_role :foo
  elseif User.group=="bar"
  user.add_role :bar
 end
end
0

There are 0 best solutions below