title: How can I pass attributes to an association through a trait in factorygirl?
body: <p>Consider the following model setup</p>
  
  <pre><code>class Template &lt; ActiveRecord::Base
    belongs_to :detail, polymorphic: true, dependent: :destroy
    accepts_nested_attributes_for :detail
  end
  
  class EbayTitleTemplate &lt; ActiveRecord::Base
    has_one  :template, as: :detail
  end
  </code></pre>
  
  <p>And here is a working factory</p>
  
  <pre><code>FactoryGirl.define do
    factory :template do
      merchant
      channel
  
      trait :ebay_title do
       association :detail, factory: :template_ebay_title
      end
  
      factory :ebay_title_template,   traits: [:ebay_title]
    end
  
    factory :template_ebay_title, class: EbayTitleTemplate do
      name        "eBay Title Template"
      title       "Super Cool Hat"
      sub_title   "Keeps the sun away"
      description "The best hat available!"
    end
  end
  </code></pre>
  
  <p>The following works for me</p>
  
  <pre><code>create(:ebay_title_template)  # creates both records, creating a new Merchant and Channel for me
  create(:ebay_title_template, merchant: Merchant.first, channel: Channel.first)  # creates both records with explicit channel and merchant
  </code></pre>
  
  <p>Now what I'd like to also do is pass in custom attributes to override the defaults.  Something like this:</p>
  
  <pre><code>create(:ebay_title_template, title: "Overwrite the title", sub_title: "Overwrite the subtitle")
  </code></pre>
  
  <p>What ends up happening is that I get the error <code>ArgumentError: Trait not registered: title</code></p>
  
  <p>Somehow FactoryGirl thinks that I'm passing in a trait or the Template factory doesn't recognize <code>title</code> as an attribute.</p>
  
  <p>I've tried using transients to allow custom args to pass through the Template and using a callback in the <code>:template_ebay_title</code> factory to map the attribute to the model column like so:</p>
  
  <pre><code>transient do
    custom_args nil
  end
  
  after(:create) do |record, evaluator|
    evaluator.custom_args.each do |key, value|
      record.key = value
    end
  end
  </code></pre>
  
  <p>And then I create like this:</p>
  
  <pre><code>create(:ebay_title_template, custom_args: {title: "Overwrite", sub_title: "Overwrite"})
  </code></pre>
  
  <p>This results in the error <code>NoMethodError: undefined method</code>custom_args' for #`</p>
  
  <p>So either there's a way to do this and I'm doing it wrong, or I need a completely new approach. Keep in mind, there will be dozens of associations that will need to be defined as traits (or something else) so I can't possibly assign specific transients to be passed through.</p>
  
  <p><em>How can I achieve my goal of creating a factory that creates the parent and the polymorphic association, allowing me to pass in arbitrary attributes for the polymorphic association, and return the parent object?</em> </p>