Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 Devise Multiple User Models STI

I am using Devise and Rails 4. I want to add multiple User Models(admin, usertype1, usertype2) such that they inherit from the main User Model. I have searched many posts and come to the conclusion that I may use CanCan, which I do not want, or I may use Single Table Inheritance.

The way I see it is to add a type string-column to my main User model I created with Devise. I will also need to extend each sub-class from the parent as in:

class Admin < User
end

class Usertype1 < User
end

class Usertype2 < User
end

My question is: what do I do next? How exactly do I know how to access the type column? Do I also need to override the Devise Controller for the current_user helper method such that I can have current_admin for example?

like image 728
Claudiu S Avatar asked Feb 14 '26 05:02

Claudiu S


1 Answers

I'm not sure this really answers the original question. I am trying to set up multiple session controllers for Devise, and it seems like it really does require multiple models for this use case. Will post back when I've got a working version.

like image 200
Jason Newell Avatar answered Feb 15 '26 19:02

Jason Newell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!