I’m using rails devise gem for users authentification, but now for my shop i must introduce user groups for discont’s, special prices, etc. How to do this with devise? Note that this is one/many-to-many, becouse every user can have many groups, and every group some users.
Also when user is registering i’t group must be for example 1.
Devise has “closed” controller (not as in authlogic). That is trouble also.
def create
super
group = Group.find_by_name("newuser")
user_group = UserGroup.create
user_group.user_id = current_user.id
user_group.group_id = group.group_id
user_group.save
end
This doesn’t necessarily have to be integrated with Devise unless I’m reading your question wrong. Just create a Group model describing the attributes of a group, and a UserGroup join model:
As for the closed controller problem, you can lift the Devise controller into your application, or create a new controller which inherits from it and thus override the methods. Read more from their link GitHub page here.
Edit: I think you are approaching this from the wrong angle. You needn’t do anything from within Devise’s controllers, but rather add a
before_savecallback to your User model.