title: Rails 5 RESTful API with advanced relations
body: <p>I have many resources with advanced relations (habtm/hm/hmt etc..), everything you can imagine, but now it's time to write a beautiful routing for this API.
  The problem is, I can't fin the best practices about nested resource + advanced relations ro do my routing, here is what I am trying to do:</p>
  
  <p>Here are my models with the concerned relations</p>
  
  <pre class="lang-rb prettyprint-override"><code># app/models/candidate.rb
  class Candidate &lt; ApplicationRecord
    include Sociable, Locatable
  
    belongs_to :user
    has_many :sourcing_accounts
    has_many :accounts, through: :sourcing_accounts
    has_many :users, through: :sourcing_accounts
  end
  
  # app/models/sourcing_account.rb
  class SourcingAccount &lt; ApplicationRecord
    belongs_to :account
    belongs_to :candidate
    belongs_to :user
  end
  
  # app/models/user.rb
  class User &lt; ApplicationRecord
    include Sociable
  
    has_many :candidates
    has_many :campaigns
    has_many :sourcing_account
  end
  </code></pre>
  
  <p>For this example, I am willing to permit to create a relation between a <code>Candidate</code> and a <code>User</code> by creating a <code>SourcingAccount</code>.</p>
  
  <pre class="lang-rb prettyprint-override"><code>resources :candidates do
    resources :accounts
    resources :users, only: [:index] do
      post :remove
      post :add
    end
  end
  </code></pre>
  
  <p>It generates:</p>
  
  <pre><code>v1_candidate_user_remove POST   /v1/candidates/:candidate_id/users/:user_id/remove(.:format) api/v1/users#remove {:subdomain=&gt;"api", :format=&gt;:json}
     v1_candidate_user_add POST   /v1/candidates/:candidate_id/users/:user_id/add(.:format)    api/v1/users#add {:subdomain=&gt;"api", :format=&gt;:json}
  </code></pre>
  
  <p>I did not found anything about this. Is there best practices ???
  If not, what do you think would be the best for this case ?</p>
  
  <p>Without precisions, Rails wants to route this to users#remove and users#add, which I think is totally wrong. These actions must not belong to the users controller. </p>
  
  <p>Bonus:</p>
  
  <p>What should look like a polymorphic route to create an <code>Account</code> belonging to 2 other models (with presence validation) the 2 models are <code>Source</code> and the other one is polymorphic <code>[Candidate,User] # for example</code>, (they are <code>Sociable</code> models) </p>