title: Rails 4 - Cannot modify association because of :has_many association
body: <p>I'm getting the following error when I attempt to submit my nested form.</p>
  
  <pre><code>Cannot modify association 'Appointment#addresses' because the source reflection class 'Address' is associated to 'User' via :has_many
  </code></pre>
  
  <p>I'm not entirely sure which part of my setup is wrong. To briefly explain, I have Users that have multiple Appointments and multiple Addresses. Each Appointment can happen at a different Address, which is why I'm doing a :has_many association through user (which is correct, right?). Why am I getting this error?</p>
  
  <p>Here are my models:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :addresses, dependent: :destroy
    has_many :appointments, dependent: :destroy
  end
  
  class Appointment &lt; ActiveRecord::Base
    belongs_to :user
    has_many :addresses, :through =&gt; :user
    accepts_nested_attributes_for :addresses
  end
  
  class Address &lt; ActiveRecord::Base
    belongs_to :user
  end
  </code></pre>
  
  <p>And this is the <code>create</code> method from my Appointments controller:</p>
  
  <pre><code>class AppointmentsController &lt; ApplicationController
  
    ...
  
    def create
      @appointment = current_user.appointments.build(appointment_params)
      @address = @appointment.addresses.build(appointment_params[:addresses_attributes]["0"])
  
      respond_to do |format|
        if @appointment.save
          format.html { redirect_to current_user, notice: 'Appointment was successfully created.' }
          format.json { render :show, status: :created, location: current_user }
        else
          format.html { render :new }
          format.json { render json: @appointment.errors, status: :unprocessable_entity }
        end
      end
    end
  
    ...
  
    private
      def appointment_params
        params.require(:appointment).permit(:appointment_date, :appointment_start_time, :appointment_end_time, :comments, :phone_number, addresses_attributes: [:user_id, :street_address, :street_address_optional, :city, :state, :zip_code, :primary])
      end
  
  end
  </code></pre>
  
  <p>And finally, this is my form in my view:</p>
  
  <pre><code>&lt;%= form_for(@appointment, :url =&gt; {:controller =&gt; "appointments", :action =&gt; "create"}, :html =&gt; {"data-abide" =&gt; ""}) do |f| %&gt;
        &lt;label&gt;
          Appointment Date
        &lt;/label&gt;
        &lt;%= f.date_select :appointment_date %&gt;
  
        &lt;label&gt;
          Appointment Timeframe Start
        &lt;/label&gt;
        &lt;%= f.time_select :appointment_start_time %&gt;
  
        &lt;label&gt;
          Appointment Timeframe End
        &lt;/label&gt;
        &lt;%= f.time_select :appointment_end_time %&gt;
  
    &lt;%= f.fields_for :addresses do |builder| %&gt;
      &lt;%= builder.hidden_field :user_id, :value =&gt; current_user.id %&gt;
  
          &lt;label&gt;
            Street Address
            &lt;%= builder.text_field :street_address %&gt;
          &lt;/label&gt;
  
          &lt;label&gt;
            Street Address (Optional)
            &lt;%= builder.text_field :street_address_optional %&gt;
          &lt;/label&gt;
  
          &lt;label&gt;
            City
            &lt;%= builder.text_field :city %&gt;
          &lt;/label&gt;
  
          &lt;label&gt;
            State
            &lt;%= builder.text_field :state %&gt;
          &lt;/label&gt;
  
          &lt;label&gt;
            Zip Code
            &lt;%= builder.number_field :zip_code %&gt;
          &lt;/label&gt;
  
          &lt;%= builder.check_box :primary %&gt;&lt;%= builder.label :primary %&gt;
  
    &lt;% end %&gt;
  
        &lt;label&gt;
          Special Instructions
          &lt;%= f.text_area :comments %&gt;
        &lt;/label&gt;
  
        &lt;%= f.submit "Sign Up", :class =&gt; "button expand"%&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>Thanks in advance for the help :)</p>