title: Undefined method - attribute is NULL after submitting form (Rails 3.2.13)
body: <p>ERROR:</p>
  
  <p><code>undefined method 'function_id' for #&lt;Person:0xa004934&gt;</code></p>
  
  <p>There is a trial management system. So far a user has been able to create new participants. Now the user should be able to create new persons, too. That person is meant to be also participant of a trial.</p>
  
  <p>We have a form to create a new person. After hitting <code>create person</code> in a form, only the person table record is OK. But the <strong>function_id</strong> attribute in the <code>participant</code> table is <strong>NULL</strong>. What is necessary to set only the value <strong>function_id</strong> in the <code>participant</code> table when the user creates a person? So when a new person is created a participant should be created always.</p>
  
  <p>There are <strong>4</strong> tables:</p>
  
  <ul>
  <li>trial <code>has_many :participants</code></li>
  <li>participant <code>belongs_to</code> person</li>
  <li>person <code>has_many participants</code>... <code>has_many</code> :trials, through: participants</li>
  <li>function <code>has_many</code> participants</li>
  </ul>
  
  <p>What works so far:</p>
  
  <p>Creating a new participant (id | trial_id | <strong>function_id</strong> | person_id) with a form <code>/views/participants/new.html.erb</code> works. Creating a new person (id | title | prename | surname etc.) with a form <code>/views/persons/new.html.erb</code> works not 100% like mentiond above.
  In the form <code>persons/new.html.erb</code> the user should be able to select an option in a dropdown box which is the function of a <code>participant</code>.</p>
  
  <p>I don't want a completly new <code>participant</code> record. I want only the <strong>function_id</strong> value. </p>
  
  <p>Below is a snippet of the <code>/persons/views/new.html.erb</code>    </p>
  
  <pre><code>&lt;%= form_for([@trial, @person]) do |f| %&gt;
  &lt;div class="table"&gt;
  &lt;fieldset&gt;
    &lt;div class="table"&gt;
      &lt;div class="tr"&gt;
        &lt;div class="th"&gt;
          &lt;%= f.label t(:function) %&gt;
        &lt;/div&gt;
        &lt;div class="tdsep"&gt;:&lt;/div&gt;
        &lt;div class="td"&gt;
         &lt;%= f.select :function_id, Function.all.collect {|fu| [fu.german, fu.id]}  %&gt;
       &lt;/div&gt;
      &lt;/div&gt;
     ...
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Person model</p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
    belongs_to :organization
    attr_accessible :organization_id,:title,:prename,:surname,:street,:street_number,:zip_code,:city,:phone,:fax,:email,:organization_description, :participants_attributes
    has_many :participants
    has_many :trials, through: :participants
  </code></pre>
  
  <p>PersonsController  </p>
  
  <pre><code>class PersonsController &lt; ApplicationController
  
   load_and_authorize_resource :person, :through =&gt; :trial, :only =&gt; [:destroy]
   before_filter :authenticate_user!, :except =&gt; [:index, :new, :create, :show]
   load_and_authorize_resource :trial
  
   def new
    @person = Person.new
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @person}
    end
  end
  
  def create
    @person = Person.new(params[:person])
    @person.trials &lt;&lt; @trial
    respond_to do |format|
      if @person.save
        format.html { redirect_to @person, notice: 'Person was successfully created.' }
        format.json { render json: @person, status: :created, location: @person }
      else
        format.html { render action: "new" }
        format.json { render json: @person.errors, status: :unprocessable_entity }
      end
    end
  end
  </code></pre>
  
  <p>Thanks in advance.</p>