title: How do I modify the creation of an associated object when done via accepts_nested_attributes_for for another object?
body: <p>I have a <code>Job</code> model, that <code>belongs_to :company</code>. Both models <code>belong_to :user</code> (i.e. the <code>current_user</code>).</p>
  
  <p><code>Job accepts_nested_attributes_for :company</code>.</p>
  
  <p>I have my company attributes on the <code>jobs/_form.html.erb</code>.</p>
  
  <p>But, what is happening is that when the company object is being created, it isn't setting an attribute I want it to (<code>company.user_id</code>).</p>
  
  <p>I am not quite sure how to force it to do that.</p>
  
  <p>This is what the log for this part of the operation looks like:</p>
  
  <pre><code>Company Exists (1.4ms)  SELECT  1 AS one FROM "companies" WHERE ("companies"."id" IS NOT NULL) AND "companies"."slug" = $1 LIMIT $2  [["slug", "phish-me"], ["LIMIT", 1]]
    SQL (2.7ms)  INSERT INTO "companies" ("name", "logo", "description", "city", "state", "country", "email", "created_at", "updated_at", "slug") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"  [["name", "Acme Corp"], ["logo", "#&lt;ActionDispatch::Http::UploadedFile:0x007f&gt;"], ["description", "Some random description."], ["city", "Leesburg"], ["state", "Virginia"], ["country", "US"], ["email", "random@email.com"], ["created_at", 2016-06-24 09:50:49 UTC], ["updated_at", 2016-06-24 09:50:49 UTC], ["slug", "acme-corp"]]
  </code></pre>
  
  <p>I even tried including a hidden field for the <code>user_id</code> in the company portion of that form and it didn't work.</p>
  
  <p>I added a <code>binding.pry</code> to my <code>Company#Create</code> action and it didn't work - so it seems that's not being called.</p>
  
  <p>I am not quite sure how to modify that Create event and ensure that <code>company.user = job.user</code></p>
  
  <p>How do I do that?</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>My <code>Jobs#Create</code></p>
  
  <pre><code>  def create
      @job = current_user.jobs.new(job_params)
  
      respond_to do |format|
        if @job.save
          if @job.premium?
            @job.update_columns(price: 200.00)
          end
          format.html { redirect_to job_checkout_path(@job), notice: 'First step complete. Before listing is published, you need to make payment below.' }
          format.json { render :show, status: :created, location: @job }
        else
          format.html { render :new }
          format.json { render json: @job.errors, status: :unprocessable_entity }
        end
      end
  </code></pre>
  
  <p>Nothing fancy happening here.</p>
  
  <p>This is my <code>jobs/_form.html.erb</code>:</p>
  
  <pre><code>&lt;%= simple_form_for(@job) do |f| %&gt;
    &lt;%= f.error_notification %&gt;
  
    &lt;div class="form-group"&gt;
      &lt;%= f.input_field :title %&gt;
    &lt;/div&gt;
  
      # truncated for brevity    
  
    &lt;div class="form-group"&gt;
      &lt;%= f.association :company, collection: [['New Company', nil]] + current_user.companies.pluck(:name, :id), include_blank: 'Please Select Company', input_html: { id: 'company-select' } %&gt;
    &lt;/div&gt;
  
    &lt;fieldset id='job-fields'&gt;
        &lt;%= f.simple_fields_for :company, @job.build_company do |ff| %&gt;
          &lt;%= ff.input :user_id, as: :hidden %&gt;
        &lt;div class="form-group"&gt;
          &lt;%= ff.input_field :name, class: "form-control", placeholder: "Company Name" %&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;%= ff.input_field :logo, as: :file, placeholder: "Upload company logo." %&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;%= ff.input_field :description, as: :text, class: "form-control", placeholder: "Enter a brief description of the company." %&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;%= ff.input_field :city, class: "form-control", placeholder: "Enter the city (E.g. San Francisco, Cleveland)" %&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;%= ff.input_field :state, class: "form-control", placeholder: "Enter the state (E.g. California, Ohio)" %&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;%= ff.input_field :email, class: "form-control", placeholder: "Contact Email Address for the company. This won't be published publicly." %&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;%= ff.input :country, class: "form-control" %&gt;
        &lt;/div&gt;
        &lt;% end %&gt;
    &lt;/fieldset&gt;
  
    &lt;div&gt;
      &lt;%= link_to "Cancel", root_path, class: "btn btn-lg btn-outline btn-danger pull-left" %&gt;&lt;/p&gt;
      &lt;%= f.button :submit, class: "btn btn-lg btn-primary pull-right" %&gt;
    &lt;/div&gt;
  
  &lt;% end %&gt;
  </code></pre>