Rails App with 3 different types of Users

我的梦境 提交于 2019-12-04 20:40:16

Instead of managing separate models for the different types of user, I've found the cancan gem to be very useful for managing user abilities and authorization. I used this blog post in the past to set it up with devise, though it may be fairly outdated by now.

I would use a few methods inside your UsersController to define what the various access levels are, for example:

@user = is_advanced?

This way you can allow them to choose the type of account they will have, store that selection in the database [users::account_type: integer]. This will allow you to let them change n the future if you decide to add that functionality.

I wouldn't create so many associations in your Users class, because it will bloat your RESTfull routes, etc and make debugging down the road a nightmare.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!