title: Update has_many association from array of ids
body: <p>I have 2 models connected with has_many through association.
  <code>Book</code> can have many authors and <code>Author</code> many books.</p>
  
  <p>In <code>AuthorsController</code> in <code>update</code> action from API I get author's id and an array of books ids <code>Parameters: {"books"=&gt;"3,4,5", "id"=&gt;"1"}</code> and I need to update author's books with them.
  What is the best way to achieve that?</p>
  
  <p>I tried <code>author.books &lt;&lt; Book.where(id: params[:books])</code> but the problem here is that if a book is already in author's books it will be duplicated.</p>