[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Inserting records on a migration question

Gene Jones

10/6/2007 11:11:00 PM

Hi,

I am trying to create a user_types table and insert two rows into it.
See code below:

class CreateUserAccountTypes < ActiveRecord::Migration
def self.up
create_table :user_types do |g|
g.column :name, :string, :default => nil
g.column :has_admin_access, :boolean, :default => false
end

UserType.create :name=> 'Member', :has_admin_access => false
UserType.create :name=> 'Admin Member', :has_admin_access => true
end

def self.down
drop_table :user_types
end
end

However I keep getting this error after running rake db:migrate
(in C:/Ruby/InstantRails/rails_apps/Eivom)
== CreateUserAccountTypes: migrating
======================================
-- create_table(:user_types)
-> 0.0220s
rake aborted!
uninitialized constant CreateUserAccountTypes::UserType

(See full trace by running task with --trace)

It works fine if I remove the "UserType.create " line. Any ideas?

Thanks
Gene

2 Answers

Gene Jones

10/6/2007 11:19:00 PM

0

Its ok, just realised I hadn't created the model first.

Thanks anyway.
Gene


On Oct 6, 6:11 pm, Gene Jones <drgenejo...@gmail.com> wrote:
> Hi,
>
> I am trying to create a user_types table and insert two rows into it.
> See code below:
>
> class CreateUserAccountTypes < ActiveRecord::Migration
> def self.up
> create_table :user_types do |g|
> g.column :name, :string, :default => nil
> g.column :has_admin_access, :boolean, :default => false
> end
>
> UserType.create :name=> 'Member', :has_admin_access => false
> UserType.create :name=> 'Admin Member', :has_admin_access => true
> end
>
> def self.down
> drop_table :user_types
> end
> end
>
> However I keep getting this error after running rake db:migrate
> (in C:/Ruby/InstantRails/rails_apps/Eivom)
> == CreateUserAccountTypes: migrating
> ======================================
> -- create_table(:user_types)
> -> 0.0220s
> rake aborted!
> uninitialized constant CreateUserAccountTypes::UserType
>
> (See full trace by running task with --trace)
>
> It works fine if I remove the "UserType.create " line. Any ideas?
>
> Thanks
> Gene


Rob Biedenharn

10/8/2007 8:14:00 PM

0