[Problem] wrong number of arguments (1 for 0)

Hi,

I’m pretty new to Rails. I’ll explain what I did.

I created a model called User. I edited the migration file to look
like this (no table name pluralization) :

class CreateUsers < ActiveRecord::Migration
def self.up
create_table :user do |t|
t.column :email, :string
t.column :password, :string
t.column :user_type_id, :string
t.column :client_id, :integer
t.column :firstname, :string
t.column :lastname, :string
t.column :write_permission, :boolean
t.column :notify, :boolean
t.column :type, :string
end
end

def self.down
drop_table :user
end
end

Since I will also have a ContactPerson which will inherit from User,
there is a “type” field.

Okay, then I migrated the database, and then used scaffolding to
generate a controller.

Now I’m trying to add some basic validation to the model, so I did
this :

class User < ActiveRecord::Base
validates_presence_of :email
end

Nothing fancy yet. But now, when I try to add a new user (using the
scaffold-generated views), I’m getting this error :

ArgumentError in UserController#create
wrong number of arguments (1 for 0)

The automatically generated create looks like this :

def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = ‘User was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

I’m a bit stuck because of this. Any help would be greatly
appreciated. Thanks!

On Wed, Mar 07, 2007 at 08:36:59AM -0800, Sven Magnus wrote :

Nothing fancy yet. But now, when I try to add a new user (using the
scaffold-generated views), I’m getting this error :

ArgumentError in UserController#create
wrong number of arguments (1 for 0)

Is params[:user] defined? Check in the logs the params hash.
Do you have (in your view) fields like <%= text_field :user, :email %> ?

BTW, did you run the console?
Just run ‘ruby script/console’ in your RAILS_ROOT and try to add your
user. You should have this behavior:

pam=User.new
=> #<User: blablabla >

pam.valid?
=> false

pam.errors.full_messages.to_sentence
=> “Email should not be blank”

pam.email=‘[email protected]
=> ‘[email protected]

pam.valid?
=> true

pam.save
=> true

Hope that helps,


,========================.
| Pierre-Alexandre M. |
| email : [email protected] |
`========================’

Thanks for your reply. I tried using the console, this is what I got :

pam=User.new
=> #<User:0x48a9180 @new_record=true,
@attributes={“user_type_id”=>nil, “type”=>
nil, “write_permission”=>nil, “client_id”=>nil, “lastname”=>nil,
“firstname”=>ni
l, “notify”=>nil, “password”=>nil, “email”=>nil}>

pam.valid?
ArgumentError: wrong number of arguments (1 for 0)

from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/
lib/active_record/callbacks.rb:328:in notify' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/ lib/active_record/callbacks.rb:328:incallback’
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/
lib/active_record/callbacks.rb:301:in `valid?’
from (irb):2

My log files seem to be empty… I’m using InstantRails (on Windows).
Is that normal?

I found the solution. I had a field in the table called notify - so
apparantly rails tried to call this instead of the correct notify
method.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs