开发者

Rails 3, Devise, Multiple Roles Sharing Same Views

开发者 https://www.devze.com 2023-04-10 06:38 出处:网络
I\'m writing a trading system and I have 3 models/roles: Buyers, Sellers and Administrators.I have generated the devise views for each of the models but I would like to use the same sign in, forgotten

I'm writing a trading system and I have 3 models/roles: Buyers, Sellers and Administrators. I have generated the devise views for each of the models but I would like to use the same sign in, forgotten password pages etc. for them, rather than maintaining 3 sets of views, is there a way o开发者_如何学运维f doing this?

The buyer and seller have similar fields (forename, surname, email address, telephone etc.), is it possible to use STI with devise and is it fairly straightforward? At the moment I have 3 separate models with no inheritance.


You can simply have a single User model with a :role attribute and also implement a simple ACL via CanCan or decl_auth (gems). This way they will all sign in etc. via the same session. Devise and CanCan is quite a popular approach and well documented online and in their respective Github wiki's.

For administrators, you can modify your validations to skip on the extra attributes and leave them as blank in the DB.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号