Forum: Ruby on Rails Weird error when running migration

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
contact (Guest)
on 2005-11-12 12:49
(Received via mailing list)
I'm having some troubles running what should be a simple migration yet
I'm
getting the error:

rake aborted!
wrong number of arguments (1 for 0)

Here is my migration (the up() method):

# initial permissions
Permission.create :name => 'NEWS_VIEW'
Permission.create :name => 'NEWS_CREATE'
Permission.create :name => 'NEWS_EDIT'
Permission.create :name => 'NEWS_DELETE'
Permission.create :name => 'NEWS_CATEGORY_CREATE'
Permission.create :name => 'NEWS_CATEGORY_EDIT'
Permission.create :name => 'NEWS_CATEGORY_DELETE'
Permission.create :name => 'NEWS_POST_COMMENT'
Permission.create :name => 'NEWS_DELETE_COMMENT'
Permission.create :name => 'KB_VIEW'
Permission.create :name => 'KB_CATEGORY_CREATE'
Permission.create :name => 'KB_CATEGORY_EDIT'
Permission.create :name => 'KB_CATEGORY_DELETE'
Permission.create :name => 'KB_ARTICLE_CREATE'
Permission.create :name => 'KB_ARTICLE_EDIT'
Permission.create :name => 'KB_ARTICLE_DELETE'

# administrator role
admin_role = Role.create :name => 'Administrator', :description => 'Top
level role with full permissions'
Permission.find(:all).each do |p|
admin_role.permissions << p
end

# create root user
root_user = User.create(
:first_name => 'Root',
:surname => 'User',
:short_name => 'Root',
:username => 'rootuser',
:password => 'rootpass',
:email_address => ' removed_email_address@domain.invalid'
)
root_user.roles << admin_role
root_user.save

The line its falling over on is the root_user = User.create method. I
don't
think its because of the way I've laid it out over several lines - I've
tried it with and without the parentheses and all on one line as well.
I've
also tried just setting one or two of the fields.

Here is my schema definition for the user table:

create_table "users", :force => true do |t|
t.column "surname", :string, :limit => 100
t.column "first_name", :string, :limit => 100
t.column "short_name", :string, :limit => 30
t.column "username", :string, :limit => 30
t.column "password", :string, :limit => 40
t.column "email_address", :string
end
add_index "users", ["id"], :name => "id", :unique => true

And here is a backtrace:

/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:465:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:465:in
`create'
./db/migrate//002_initial_user_data.rb:29:in `up'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:211:in
`migrate'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:206:in
`each'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:206:in
`migrate'
/usr/lib/ruby/gems/1.8/gems/activerecord-
1.13.0/lib/active_record/migration.rb:173:in
`up'
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/migration.rb:164:in
`migrate'
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/tasks/databases.rake:3
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/tasks/databases.rake:2:in
`call'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:202:in `each'
/usr/lib/ruby/gems/1.8/gems/rake- 0.6.2/lib/rake.rb:202:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:180:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake.rb:1454:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.6.2/bin/rake:7
/usr/bin/rake:18

Help! I'm stumped.

Cheers
Luke
jamis (Guest)
on 2005-11-12 12:49
(Received via mailing list)
What does your User model look like? Have you defined an initialize
method for it? (That's kind of what it looks like, from the backtrace
anyway). If so, please note that the initialize method is special for
ActiveRecord, and you should use the after_find/after_initialize
hooks to do on-creation initialization, rather than overriding the
initialize method.

- Jamis
contact (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Ah! Thanks Jamis, yes, I did have an initialize method. I will change
this.

Cheers
Luke
croeder (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Hi,

I was wondering if anyone has any experience with livetree, or knows
where to find people that do.

thanks
-Chris
croeder (Guest)
on 2005-11-12 12:49
(Received via mailing list)
sorry about the subject the first time....
This topic is locked and can not be replied to.