title: How do you use a single select dropdown with Rails has_many through association?
body: <p>I can't figure out how to get a single select dropdown for a Rails has_many through association to work. I can only get multiple checkboxes or a multiple-select to work.</p>
  
  <p>How do you have a rails has_many through relationship where you want the user to only be able to select one option from the associated collection through a single select drop down?</p>
  
  <p>Here are my models</p>
  
  <pre><code>class Artist &lt; ApplicationRecord
    has_many :topics
    has_many :quotes, through: :topics
  end
  
  class Topic &lt; ApplicationRecord
    belongs_to :artist
    belongs_to :quote
  end
  
  class Quote &lt; ApplicationRecord
    has_many :topics
    has_many :artists, through: :topics
  end
  </code></pre>
  
  <p>Here is my create action and params in the Quotes controller:</p>
  
  <pre><code>  def create
      @quote = current_user.quotes.build(quote_params)
      if @quote.save
        flash[:success] = "Quote created!"
        redirect_to root_url
      else
        @feed_items = []
        render 'static_pages/home'
      end
    end
  </code></pre>
  
  <p>And here are the form fields that work:</p>
  
  <pre><code>&lt;%= f.collection_select(:artist_ids, Artist.all, :id, :name,
        {}, { :multiple =&gt; true } ) %&gt;
  
  &lt;%= f.collection_check_boxes(:artist_ids, Artist.all, :id, :name ) %&gt;
  </code></pre>
  
  <p>If I use this to make a single select drop down it just displays the dropdown with the correct collection, but then doesn't seem to save on submit and doesn't display in the view:</p>
  
  <pre><code>&lt;%= f.collection_select(:artist_ids, Artist.all, :id, :name ) %&gt;
  </code></pre>
  
  <p>For the two form fields that do work I can display the results in the view with this:</p>
  
  <pre><code>&lt;% quote.artists.each do |artist| %&gt;
    &lt;%= artist.name %&gt; - It worked!
  &lt;% end %&gt;
  </code></pre>
  
  <p>But I don't want a multi-select dropdown. I just want a dropdown where you can only select and submit one option. How do you do this?</p>