I am trying to start my first project after going though the Depot application in prog prog''s book. For some reason one of my migrations keeps bombing. I just try to setup a couple tables with some default information and even with changing the name of the second table and other minor tweaks it just does not work. I am connected to the db, the first table does get filled out. Any help is appreciated! Here is what I''ve done so far:>ruby script\generate model employees >ruby script\generate migration add_employee_data >ruby script\generate model cost_codes >ruby script\generate migration add_cost_code_dataThen inside the first 3 migrations everything goes ok - 001 class CreateEmployees < ActiveRecord::Migration def self.up create_table :employees do |t| t.column :employee_number, :integer t.column :name, :string t.column :location, :string t.column :department, :integer t.column :company_code, :string end end def self.down drop_table :employees end end 002 class AddEmployeeData < ActiveRecord::Migration def self.up Employee.create( :employee_number => ''1234'', :name => ''Bob B'', :location => ''Office'', :department => ''07'', :company_code => ''003'') end def self.down Employee.delete_all end end 003 class CreateCostCodes < ActiveRecord::Migration def self.up create_table :cost_codes do |t| t.column :job, :integer t.column :code, :integer t.column :description, :string end end def self.down drop_table :cost_codes end end This is the migration that fails with an error of ''uninitalized constant cost_code'' Anyone know what I am doing wrong? 004 class AddCodeCodeData < ActiveRecord::Migration def self.up Costcode.create( :job => ''0'', :code => ''5001'', :description => ''Other administrative (non-job related)'' ) end def self.down Costcode.delete_all end end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060710/4f28c073/attachment.html
On 7/10/06, bob brazeau <bobbrazeau@gmail.com> wrote: <snip/> Any help is appreciated!> > Here is what I''ve done so far: > >ruby script\generate model employees > >ruby script\generate migration add_employee_data > >ruby script\generate model cost_codes > >ruby script\generate migration add_cost_code_data >Looks like you generated a plural cost_codes model, did you mean to do that? This is the migration that fails with an error of '' uninitalized constant> cost_code'' Anyone know what I am doing wrong? > > 004 > class AddCodeCodeData < ActiveRecord::Migration > def self.up > Costcode.create( > :job => ''0'', > :code => ''5001'', > :description => ''Other administrative (non-job related)'' ) > end > > def self.down > Costcode.delete_all > end > end >If indeed your model is named CodeCodes as specified in your generator statement above then you would need to replace each ''Costcode'' with ''CostCodes'' Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060710/ef957494/attachment-0001.html
On Jul 10, 2006, at 12:22 PM, bob brazeau wrote:> 003 > class CreateCostCodes < ActiveRecord::Migration > def self.up > create_table :cost_codes do |t| > t.column :job, :integer > t.column :code, :integer > t.column :description, :string > end > end > > def self.down > drop_table :cost_codes > end > end > > > This is the migration that fails with an error of '' uninitalized > constant cost_code'' Anyone know what I am doing wrong? > > 004 > class AddCodeCodeData < ActiveRecord::Migration > def self.up > Costcode.create( > :job => ''0'', > :code => ''5001'', > :description => ''Other administrative (non-job related)'' ) > end > > def self.down > Costcode.delete_all > end > endCamelCase class name for cost_codes table would be: CostCode -- -- Tom Mornini -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060710/d25eef93/attachment.html