# ArgumentError

**URL:** <https://www.ruby-forum.com/t/argumenterror/118248>\
**Category:** Rails\
**Created:** [October 25, 2007, 3:33am UTC](https://www.ruby-forum.com/t/argumenterror/118248 "2007-10-25T03:33:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [October 25, 2007, 3:33am UTC](https://www.ruby-forum.com/t/argumenterror/118248/1 "2007-10-25T03:33:52Z")

</div>

hi, i’m very new to RoR,

i’m following an example on the book (Agile Web D. with Rails  
2nd ed.)

i met an error that goes like this (even though i followed the book word  
for word)

> >

ArgumentError in Login#add\_user  
Showing app/views/login/add\_user.rhtml where line #16 raised:

wrong number of arguments (0 for 1)

Extracted source (around line #16):

13:  
14:

15: Password:  
16: \<%= form.password\_field :password, :size =\> 40 %\>  
17:

  
18:  
19: 

here are my .rb and .rhtml

add\_user.rhtml:

\<%= error\_messages\_for ‘user’ %\>

 Enter User Details

```
<% form_for :user do |form| %>
  <p>
    <label for="user_name">Name:</label>
    <%= form.text_field :name, :size => 40 %>
  </p>

  <p>
    <label for="user_password">Password:</label>
    <%= form.password_field :password, :size => 40 %>
  </p>

  <p>
    <label for="user_password_confirmation">Confirm:</label>
    <%= form.password_field :password_confirmation, :size => 40 %>
  </p>

  <%= submit_tag "Add User", :class => "submit" %>

<% end %>

```

* * *

login\_controller.rb:

class LoginController \< ApplicationController

layout “admin”

def add\_user  
@user = User.new(params[:user])  
if request.post? and @user.save  
flash.now[:notice] = “User #{@user.name} created”  
@user = User.new  
end  
end

def login  
end

def logout  
end

def index  
end

def delete\_user  
end

def list\_user  
end  
end

* * *

user.rb:

require ‘digest/sha1’

class User \< ActiveRecord::Base

validates\_presence\_of :name  
validates\_uniqueness\_of :name

attr\_accessor :password\_confirmation  
validates\_confirmation\_of :password

def validate  
errors.add\_to\_base(“Missing password!!!” ) if  
hashed\_password.blank?  
end

def self.authenticate(name, password)  
user = self.find\_by\_name(name)  
if user  
expected\_password = encrypted\_password(password, user.salt)  
if user.hashed\_password != expected\_password  
user = nil  
end  
end  
user  
end

def password  
@password  
end

def password(pwd)  
@password = pwd  
create\_new\_salt  
self.hashed\_password = User.encrypted\_password(self.password,  
self.salt)  
end

private

```
def self.encrypted_password(password, salt)
  string_to_hash = password + "wibble" + salt
  Digest::SHA1.hexdigest(string_to_hash)
end

def create_new_salt
  self.salt = self.object_id.to_s + rand.to_s
end

```

end

* * *

Thanks alot in advance, i’m really lost here!

---

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [October 25, 2007, 9:38am UTC](https://www.ruby-forum.com/t/argumenterror/118248/2 "2007-10-25T09:38:20Z")

</div>

On 25 Oct 2007, at 02:33, Jojo M. wrote:

> i met an error that goes like this (even though i followed the book  
> word  
> for word)  
> but not symbol for symbol :\_
> 
> > >
> 
> ArgumentError in Login#add\_user  
> Showing app/views/login/add\_user.rhtml where line #16 raised:
> 
> wrong number of arguments (0 for 1)
> 
> Extracted source (around line #16):  
> 16: \<%= form.password\_field :password, :size =\> 40 %\>

> def password  
> @password  
> end
> 
> def password(pwd)  
> @password = pwd  
> create\_new\_salt  
> self.hashed\_password = User.encrypted\_password(self.password,  
> self.salt)  
> end

So line 16 is trying to read the password attribute, ie it tries to  
call the password method. You’ve defined the password method as  
taking one argument, so it all falls over.  
You probably meant  
def password=(pwd)  
@password = pwd  
…  
end

Fred

---

<div class="post-metadata">

**Author:** ![jojobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@jojobert](https://www.ruby-forum.com/u/jojobert)\
**Post date:** [October 25, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/argumenterror/118248/3 "2007-10-25T19:41:45Z")

</div>

On 10/25/07, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > end
> 
> So line 16 is trying to read the password attribute, ie it tries to  
> call the password method. You’ve defined the password method as  
> taking one argument, so it all falls over.

Just to beat the h3ll out of the obvious. He RE-defined the password  
method.

The fact that Ruby considers only the method name and not the  
parameters is something which trips up folks who have used languages  
like C++ and Java and are expecting to be able to overload methods.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
