title: Ruby on Rails: How do you seed the *_type column in polymorphic models?
body: <p>I have a lot of data that I'm trying to seed into a polymorphic model in Rails 2.3.8. The association for all of the data is with the County model. The data looks like:</p>
  
  <pre><code>data = Datum.create([
    ...
    { :value =&gt; '14389', :value_type =&gt; County, :value_id =&gt;'3103'},
    { :value =&gt; '59013', :value_type =&gt; County, :value_id =&gt;'3105'},
    { :value =&gt; '17117', :value_type =&gt; County, :value_id =&gt;'3106'},
    ...
  ])
  </code></pre>
  
  <p>The :value_type => County values lead to "undefined method `base_class' for String:Class."</p>
  
  <p>I have tens of thousands of these values that I would like to seed into the database. They are similar to the values above except some are associated with the County model, some with the State model, and some with the City model. They are static values that will not be edited after seeding into the database.</p>
  
  <p>How do I seed the model into the :value_type field?</p>
  
  <p>(or... am I approaching this incorrectly and if so, how would you approach it?)</p>
  
  <p>Edit: The relevant part of the schema.rb file:</p>
  
  <p>Isaac - </p>
  
  <pre><code>create_table "data", :force =&gt; true do |t|
    t.integer  "value"
    t.string   "value_type"
    t.integer  "value_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  
  create_table "counties", :force =&gt; true do |t|
    t.string   "name"
    t.integer  "state_id"
    t.integer  "ansi_code"
    t.string   "ansi_class"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  </code></pre>
  
  <p>I tried the following on the seeding, too, and it didn't work (County in quotes):</p>
  
  <pre><code>{ :value =&gt; '14389', :value_type =&gt; 'County', :value_id =&gt;'3103'},
  </code></pre>