title: Rails 4 - Assigning values for a row in an associated table in a form
body: <p>Beginner of rails here, for my project I need to create a client with things such as first name, middle name, last name and their passport. I have another table called passports that will store the passport. I want to be able to add a passport number in association with the client. Here are the relevant pieces of code:</p>
  
  <p>Controller for Client</p>
  
  <pre><code>def new
    @client = Client.new
  end
  def create
    @client = Client.new(client_params)
    if @client.save
      redirect_to root_url
    else
      render 'new'
    end
  end
  
  private
    def client_params
      params.require(:client).permit(:firstname, :middlename, :lastname, :PresentAddress)
    end
  end
  </code></pre>
  
  <p>Controller for Passport</p>
  
  <pre><code>def new
      @passport = Passport.new
  end
  def create
      passport = Passport.new(passport_params)
      if @passport.save
          flash[:notice] = "Passport saved"
      else
          flash[:notice] = "Passport not saved"
      end
  end
  private
      def passport_params
          params.require(:passport).permit(:idnumber, :country)
      end
  end
  </code></pre>
  
  <p>Model for Client</p>
  
  <pre><code>has_one :passport, foreign_key: "client_id"
  </code></pre>
  
  <p>Model for Passport</p>
  
  <pre><code>belongs_to :client
  </code></pre>
  
  <p>Migration file for client</p>
  
  <pre><code>create_table :clients do |t|
    t.string :firstname
    t.string :middlename
    t.string :lastname
  end
  </code></pre>
  
  <p>Migration file for passport</p>
  
  <pre><code>create_table :passport do |t|
    t.string :passport
  end
  </code></pre>
  
  <p>/clients/_form.html.erb</p>
  
  <pre><code>&lt;%= form_for(@client) do |f| %&gt;
    &lt;%= f.label :"First Name"%&gt;
    &lt;%= f.text_field :firstname%&gt;
    &lt;%= f.label :"Middle Name"%&gt;
    &lt;%= f.text_field :middlename%&gt;
    &lt;%= f.label :"Last Name"%&gt;
    &lt;%= f.text_field :lastname%&gt;
  &lt;%= f.submit "Create Client" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>/passport/_form.html.erb</p>
  
  <pre><code>&lt;%= form_for([@client, @client.passport.build]) do |f| %&gt;
      &lt;%= f.label :"Passport ID Number" %&gt;
      &lt;%= f.text_field :idnumber %&gt;
      &lt;% f.submit "Create Passport" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>/clients/new.html.erb</p>
  
  <pre><code>&lt;%= render "clients/form" %&gt;
  &lt;%= render "passports/new" %&gt;
  </code></pre>
  
  <p>I want to be able to create a passport for the client in this form and send it to my Postgres database. How would I go about doing that? Please let me know if I'm missing any other information.</p>
  
  <p><strong>EDIT</strong> - changed to a field that's more simple for now. Also modified to do what ChiefrockaChris suggested. </p>