I am building an app in which the users can have different roles (like seller, buyer, agency, etc). So my plan is use polymorphic association, build a class for each of the roles, and associate each instance with one user account. Each user can only be of one of those types, and after reading on the subject I concluded that this is better than using STI, but correct me if I am wrong.
So the app will have different sign up screens for the main types of user accounts. For instance, in the Seller sign up form, what will happen is that the user will fill in the details required for his user account and the fields specific for the Seller profile.
So this form should create the user object, and then the seller object associated to the former. How do you handle this? My guess is that this form should correspond to the ‘new’ action of the sellers controller, and in the create action the user account should be created before finally creating the seller.
Is this correct? If so, should I call the User controller create action from the Seller controller, or call directly the User model? If it’s the former please provide some example code, because I am not sure about how I should call one controller from another.
EDIT: I also considered using a multipart form, which is probably easier, but before deciding I want to check out this option.
If you’re bent on doing it this way, I’d say just call the model from the create method of the Seller controller. What type of relationship do you have between the User model and the Seller model? Because you’d need to do something like this:
Here I just assumed you have a
belongs_to :userin the Seller model. Still I would advise you to consider a gem like cancan or something to handle roles instead of this approach.Good luck!