title: How to connect two exisitng Objects in Rails via onclick?
body: <p>I have User Model and Car Model. <br> 
  I show a add button in the cars/index.html.erb for every Car so that a User can add any Car he want.
  And in the users/show.html.erb i want to list all the Cars he added.<br> 
  The Problem is, it connect not only the clicked Car to the User, but also all other cars in the cars/index.html.erb.</p>
  
  <p><br>   </p>
  
  <p>user.erb and car.erb </p>
  
  <pre><code>class User &lt;&lt; ActiveRecord::Base
     has_many :cars 
  end
  
  class Car &lt;&lt; ActiveRecord::Base
     belongs_to :user
  end
  </code></pre>
  
  <p><br> 
  cars/index.html.erb</p>
  
  <pre><code> &lt;% @car.each do |car| %&gt;
      #...
      &lt;td&gt;&lt;%= link_to 'Get Car', '#', :onclick =&gt; get_car(car.id) %&gt;&lt;/td&gt;
      #...
   &lt;% end %&gt;
  </code></pre>
  
  <p><br><br>
  cars_helper.rb</p>
  
  <pre><code>def get_car(id)
   current_user.cars &lt;&lt; Car.find_by(id: id)
  end
  </code></pre>
  
  <p><br> 
  user/show.html.erb</p>
  
  <pre><code>&lt;% if @user.cars.any? %&gt;  
  &lt;% @user.cars.each do |c| %&gt;
     &lt;%= c.name %&gt;
  &lt;% end %&gt;
  </code></pre>