what is the proper syntax for seeding a child table?

I'm trying to seed a parent table and a child table. Seeding the parent works fine but I don't know the syntax for seeding the child. Please help.

    b[0]=[1231215,'Jeremy', 'G', '9177477337',
   'jt@gmail.com', 'Central Ave', 'Rockaway', 'NY', ' 12291', '76 Son Court',
   'ft lauderdale','Florida', '32423', '1', '0', '1', '1', '1', '1', '0', '0', '1',          '0', '9.95', 
  'Honda', '2012', 'Civic', '2.4 Turbo', 'Special', '1J474GFGDHDH8883334D0','fart monkey trap']

   b[1]=[46545465,'Se', 'Wof', '521428788',
   'steven.j.wolfman@gmail.com', '13 NE 17 Street', 'broward', 'FL', ' 32222', '13 NE 17 Street',
   'boca','Florida', '32222', '0', '0', '1', 
   '0', '0', '1', '1', 
   '1', '1', '1', '19.95', 
   'Ford', '2012', 'Taurus', '4.0', 'Faster', '3458GDHD3YU34D0','it smells']

   while i<2 do
        :devphone=> b[i][3],
print "\n#{@customer.id}\n"

Up till this point the code works fine. When I add in the next 5 lines the code doesn't work.


This is the error I get when running db:seed: rake aborted! undefined method `Contact' for #

This is the Customer Base

      class Customer < ActiveRecord::Base
      attr_accessible :Engine, :Make, :Model, :VehicleSystem, :Year, :address, :autocrash, :baddress, :bcity, :bstate, :bzip, :carfind, :city, :crisisass, :devphone, :email, :emergencyass, :familytrack, :fname, :lname, :lowbatt, :monthlycost, :password, :remotediag, :roadass, :signupdate, :state,:stolenveh, :towalerts, :uid, :vinnum, :zip
      validates :email, :address,:fname, :lname, :password, :state, :uid, :zip, :presence => true
      has_many :Contacts

This is the Contact Base

      class Contact < ActiveRecord::Base
        attr_accessible :contactmethod, :contacttype, :customer_id, :dateadded
        validates :contactmethod, :contacttype, :customer_id, :presence => true
        belongs_to :Customer

Answer The answer to this question is that you can't require the presense of customer_id. Therefore, you just have to modify the validation by deleting :customer_id:

  class Contact < ActiveRecord::Base
    attr_accessible :contactmethod, :contacttype, :customer_id, :dateadded
    validates :contactmethod, :contacttype, :presence => true
    belongs_to :Customer


Firstly don't name you variables with an @ symbol pre-pended, this is for instance variables in controllers and view, seed.rb is neither of those things.

Second of all, you have made the file very hard to understand, try simplifying it eg.

customer1 = Customer.create(
  # all of customer 1's details here
contact_for_customer_1 = Contact.create(
  customer_id: customer1.id,
  # customer 1's contact details
customer2 = Customer.create(
  # all of customer 2's details here
contact_for_customer_2 = Contact.create(
  customer_id: customer2.id,
  # customer 2's contact details

This will work and is easy to understand. You've already put all the customer details into the file right, so you may as well lay it out nicely. No need to store the details in an array and then build the customer's from there, just put lay it out more verbosely.

Need Your Help

iOS 8 Today Widget - SLComposeViewController not displaying properly

ios objective-c ios8 ios-app-extension today-extension

I've created an extension, in fact a Today Widget, using Xcode 6 and run it on my iOS 8 beta device (I am a registered iOS developer).

willRotateToInterfaceOrientation not working in Universal MasterDetail app

objective-c ios xcode ipad

So I have this code for changing the image on my UIImage view. And I get a very strange behavior both on iPad and iPhone.