Association is duplicated on form error
<p>I need to save the same association twice, so I have this in my controller:</p>

<pre><code>def new
  @negocio = Negocio.new
  @setores = Setor.all.collect { |s| [s.nome, s.id] }
  2.times { @negocio.negocios_setores.build }
end

def create
  @negocio = Negocio.new(negocios_params)
  respond_to do |format|
    if @negocio.save
      format.html { redirect_to negocio_path(@negocio) }
    else
      format.html {
        flash.now[:alert] = I18n.t("negocios.erro")
        render action: :new
      }
    end
  end
end

def edit
  @negocio = Negocio.find(params[:id])
  @setores = Setor.all.collect { |s| [s.nome, s.id] }
end

def update
  @negocio = Negocio.find(params[:id])
  respond_to do |format|
    if @negocio.update(negocios_params)
      format.html { redirect_to negocio_path(@negocio), notice: I18n.t("negocios.atualizado") }
    else
      format.html {
        flash.now[:alert] = I18n.t("negocios.erro")
        render :edit
      }
    end
  end
end
</code></pre>

<p>And I have this in my form:</p>

<pre><code>= f.simple_fields_for :negocios_setores, wrapper: false do |s|
  .col-md-6
    = s.input :setor_id, collection: @setores, input_html: { class: "chosen-select" }
</code></pre>

<p>And my model has:</p>

<pre><code>has_many :negocios_setores
has_many :setores, through: :negocios_setores

accepts_nested_attributes_for :negocios_setores
</code></pre>

<p>The thing is, it works fine when I'm creating the object. If the error is thrown, it doesn't duplicate the association. When I try to update the object, the page throws an error and I end up with 4 select boxes.</p>

<p>Can someone please help me understand this?</p>