multiple user types with self references rails
<p>I am working on an app in rails where I need to make multiple types of users. I am using Devise gem for authentication. Now let me give you an overview what I am trying to achieve and could not for past whole week.</p>

<p>First, I want 2 types of users. Let us call them Client and Developer as shown below.</p>

<pre><code>class Client &lt; ActiveRecord::Base

end

class Developer &lt; ActiveRecord::Base

end
</code></pre>

<p>Now, these 2 users have many to many relation with each other. A client can have many developers and a developer can also work for many clients. So, for that, we will need a middle table as well. Let us call it client_developer_join.</p>

<p>So, let us update our models accordingly.</p>

<pre><code>class Client &lt; ActiveRecord::Base
    has_many :developers, through: :client_developer_joins, dependent: :nullify
    has_many :client_developer_joins, dependent: :destroy
end

class Developer &lt; ActiveRecord::Base
    has_many :clients, through: :client_developer_joins, dependent: :nullify
    has_many :client_developer_joins, dependent: :destroy
end

class ClientDeveloperJoin &lt; ActiveRecord::Base
    belongs_to :client
    belongs_to :developer
end
</code></pre>

<p>Important:</p>

<p>Now, what I want is that when a user sign up, he will be given the ability to choose whether to sign up as a Client or a Developer using radio buttton or some other good looking thing. There will also be a third option named "Both". In that case, user will have the option to switch from Client to Developer and vice versa whenever he wants.</p>

<p>How can I acheive without creating multiple sign up and sign in forms for each type of user and give them the ability to switch.</p>

<p>I have looked into STI (Single Table Inheritance) and all the questions on StackoverFlow related to that but could not solve the problem.</p>

<p>One solution that I think is ideal but do not know how to achieve is to have seperate devise models for each type of user but that will create different sign up and sign in forms for that. I do not want that and it will also not give me the ability to switch from the one type to another type.</p>