title: Model creation and association of STI subclass
body: <p>I have an Event model that has one Payoption which can be of different types using STI subclasses like this:</p>
  
  <pre><code>class Event &lt; ActiveRecord::Base
      has_one :payoption, dependent: :destroy
      accepts_nested_attributes_for :payoption    
  end
  
  class Payoption &lt; ActiveRecord::Base
      belongs_to :event, :polymorphic =&gt; true
  
  PAY_OPTION = ["BankPayoption", "CashPayoption"]
  end
  
  class BankPayoption &lt; Payoption
      belongs_to :event
  end
  
  class CashPayoption &lt; Payoption
      belongs_to :event
  end
  </code></pre>
  
  <p>I'm creating an Event and a Cash/BankPayoption in the same controller like this, still some hardcoding and missing functionally while developing:       </p>
  
  <pre><code>def new
      @event = Event.new
      @event.build_payoption
  end  
  
  def create
  
      @event = Event.new(event_params)
      @event.user_id = current_user.id
  
      if params[:event][:payoption_attributes][:type] == "BankPayoption"
          @payoption = BankPayoption.new
          @payoption.phone = "0734176395"
          @payoption.event = @event
          @payoption.save
          @event.payoption = @payoption
      end
  
      @event.save
      redirect_to @event
  end
  </code></pre>
  
  <p>Both the Event and BankPayoption gets created and BankPayoption gets the corrent Event ID however the Event doesn't get any Payoption ID at all and remains nil. Figured there's issues with the STI/polymorphism but can't figure out how to solve it.</p>
  
  <p>Thanks in advance</p>