title: How to use Selectize.js to find or create a rails belongs_to association?
body: <p>I'm having a hard time figuring out how to combine <a href="https://selectize.github.io/selectize.js/" rel="noreferrer">Selectize.js</a> with a belongs_to association in rails. I want to do something like this photo:</p>
  
  <p><a href="https://i.stack.imgur.com/ol65m.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ol65m.png" alt="enter image description here"></a></p>
  
  <p>I've attempted using <code>accepts_nested_attributes</code>, but that doesn't seem to work with a <code>belongs_to</code> relationship.</p>
  
  <p>I tried doing an auto-complete association like this <a href="http://railscasts.com/episodes/102-auto-complete-association-revised?view=asciicast" rel="noreferrer">railscast episode</a>.</p>
  
  <p>What I'd really like to do is use a Selectize style collection select to create the "Speaker" association if it's already in the database, but add a new one if it doesn't yet exist. Selectize enables me to add a new one, but I'm having trouble passing that through the form to create the new record in the associated model.  </p>
  
  <p>Here are my models:</p>
  
  <pre><code>class Quote &lt; ApplicationRecord
    belongs_to :speaker,  class_name: "Artist"
    belongs_to :topic,    class_name: "Artist"
  end
  </code></pre>
  
  <p><a href="https://gist.github.com/leemcalilly/f1f44617574b9706e415f342913e04b0" rel="noreferrer">Quote.rb</a></p>
  
  <pre><code>class Artist &lt; ApplicationRecord
    has_many :spoken_quotes, class_name: "Quote", foreign_key: :speaker_id
    has_many :topic_quotes,  class_name: "Quote", foreign_key: :topic_id
  end
  </code></pre>
  
  <p><a href="https://gist.github.com/leemcalilly/de615ea146159bb19059f5b68ad410c4" rel="noreferrer">Artist.rb</a></p>
  
  <p>And my form:</p>
  
  <pre><code>&lt;%= f.label :speaker, 'Who said it?' %&gt;
  &lt;%= f.collection_select :speaker_id, Artist.order(:name), :id, :name, {prompt: 'Select an artist'}, {class: 'form-control select-artist'} %&gt;
  </code></pre>
  
  <p><a href="https://gist.github.com/leemcalilly/2493f9b65025e6263eb1c99c94b35866" rel="noreferrer">_form.html.erb</a></p>
  
  <p>Controllers:</p>
  
  <p><a href="https://gist.github.com/leemcalilly/f9936be771d5bad500ee42ba53babd7a" rel="noreferrer">quotes_controller.rb</a></p>
  
  <p><a href="https://gist.github.com/leemcalilly/805020f958e09da21fd5dc48f4e099df" rel="noreferrer">artists_controller.rb</a></p>
  
  <p>How can I create a new Artist (as "Speaker") through the Quote.new form through the Selective-style collection select? The Selectize behavior is the user experience I'm looking for, I just can't figure out how to create the new Artist through the Quote form.</p>