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!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Pierre-Alexandre Meyer
2007-Mar-07 16:53 UTC
Re: [Problem] wrong number of arguments (1 for 0)
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=''dave-qt+rEuLeqy0@public.gmane.org''=> ''dave-qt+rEuLeqy0@public.gmane.org''>> pam.valid?=> true>> pam.save=> true Hope that helps, -- ,========================. | Pierre-Alexandre Meyer | | email : pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org | `========================'' --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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:in `callback'' 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? On 7 mrt, 17:53, Pierre-Alexandre Meyer <p...-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org> wrote:> 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=''d...-qt+rEuLeqy0@public.gmane.org'' > > => ''...@null.org''>> pam.valid? > => true > >> pam.save > > => true > > Hope that helps, > > -- > ,========================. > | Pierre-Alexandre Meyer | > | email : p...-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org | > `========================''--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On 7 mrt, 18:38, "Sven Magnus" <svens...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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:in `callback'' > 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? > > On 7 mrt, 17:53, Pierre-Alexandre Meyer <p...-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org> wrote: > > > On Wed, Mar 07, 2007 at 08:36:59AM -0800,SvenMagnuswrote : > > > > 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=''d...-qt+rEuLeqy0@public.gmane.org'' > > > => ''...@null.org''>> pam.valid? > > => true > > >> pam.save > > > => true > > > Hope that helps, > > > -- > > ,========================. > > | Pierre-Alexandre Meyer | > > | email : p...-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org | > > `========================''--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---