I have been trying to create an ideal way to have multiple users in Rails. The idea is that there is only a single login and a single registration regardless of the number of user models.
The other option will be a single user model, but I do not want all the fields of all my models to be in one, since as you know there are fields in the "Company" model, which have nothing to do with the model "Client", or "Advisor" Model, so I would like that unique model, either called "User" or "Account", only have common fields and the other models the respective fields in each of them.
Possible solutions without success at the moment:
1.STI (Single Table Inheritance) It allows me to have only one table, and that the models of "Company", "Advisor", "Client", inherit from it, but it forces me to have all the fields in the model Father "User" or "Account" depending on his name, in the intention to put only common fields in the Parent model and put the fields in the respective models individually, it is impossible for me, since when inheriting from User, they can not interact in case alone with the BD, because the inheritance would be something like this: Class Enterprise < User, instead of how normal it would be: Class Enterprise < ActiveRecord :: Base
2.Polimorphism, this idea is great, however at the time of translating it, I had obviated that the company, client or adviser should already exist to make the connection with user, otherwise, userable will not be able to find the id and the type of the associated model. The idea is that the moment of the registration asks you what you want to be: "Company", "Client" or "Advisor", depending on what you request, a nested_form is displayed within the registration form, bringing the necessary fields from the user model to which I select, so that I continue completing the fields such as: "Type of company", "Address", "Telephone", etc. So in theory the company should also be created at the time of registering as User where only the fields of "Email, Password, Name" will be displayed and the nested will bring me the fields of the model to which reference is made, taking as an example the fields of the above mentioned company. But for this to work, the company must already exist. So you can take the userable_id, userable_type
I hope you can help me friends, greetings!