Hi everybody temporary i'm working on some rails project where i have one super admin which can create company, employee, resources also he can to add employee in the some company employee can to have many resources etc. The problem which i have here is: How i can create manager for each Company separately, super admin should to have ability to create manager for company. And than when manager going to do login he should just have information about his company. What is the best way for this if somebody already had experience with something like this would be great:) Tnx in advance!
This sounds like a good use case for just a single User model with roles. Everyone can login from the same spot and then based upon their role, they can access various different things. The benefit of doing roles is that you can easily re-assign people jobs rather than having them have separate accounts to login with each time.
I haven't done an episode on this (yet!) but Rolify is a pretty good starting point unless you want to build something from scratch. https://github.com/RolifyCommunity/rolify
Hey Chris now working fine, i was a little bit confused when i came here again and looked and big form for comment :D
Hey i thought i could use pundit for authorization and already i added role column in my user table and it working fine. But my problem here is how i can with user which have role :admin create another user which have role :manager for example and than that user can be logged in into my system and have certain permission?
If you need an admin to create other users, you can make a new controller that only the admin can access to create the other users. I would recommend using devise_invitable to send invitiations to those users. This sort of setup would let you add other users and set their roles. You can then authorize this controller to only allow admins to add users.
# You don't want this to conflict with devise URLs, so we namespace it namespace :settings do routes :users end
class Settings::UsersController < ApplicationController def create User.invite!(user_params) end private def user_params params.require(:user).permit(:email, :role) end end
Hm i will try to do something like this: I will create new rails devise for manager than i will make association between manager and company has_one. But from this point how i can connect login for manager and admin in the same form on the site? And how i can allow admin to create manager but without devise_invitable just like normal, i have some list of managers where i can create, update, delete manager, and than when i'm creating new company i will have select control to choose manager for that company. What you mean, is this possible to do this on this way?
Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.