# Wrong number of arguments (1 for 0)

**URL:** <https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451>\
**Category:** Rails\
**Created:** [March 10, 2008, 7:37am UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451 "2008-03-10T07:37:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 7:37am UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/1 "2008-03-10T07:37:42Z")

</div>

I’m getting a wrong number of arguments (1 for 0) error. This happens  
when I attempt to login to my app. Also, I upgraded to Ruby 1.8.6, from  
1.8.2 (i think)  
Heres the code:

— login.rhtml

\<% form\_tag do %\>

| **Sign-in to BancOffice** |
| Company Code: | \<%= text\_field\_tag :account\_code, params[:account\_code] %\> |
| User name: | \<%= text\_field\_tag :username, params[:username] %\> |
| Password: | \<%= password\_field\_tag :password, params[:password] %\> |
| | \<%= submit\_tag "Login" %\> |

\<% end %\>
* * *

logincontroller.rb

def login  
session[:user\_id] = nil  
if request.post?  
employee = Employee.authenticate(params[:username],  
params[:password], params[:account\_code])  
if employee  
session[:user\_id] = employee.id  
session[:account\_id] = employee.account\_id  
@option = Option.find\_by\_employee\_id(employee.id)  
session[:admin\_yn] = @option.admin\_yn  
redirect\_to(:controller =\> “dashboard”, :action =\> “show”)  
else  
flash[:notice] = “Invalid user/password  
combination”  
end  
end  
end

# employee.authenticate is line called for error

* * *

employee.rb

def self.authenticate(username, password, account\_code)  
if employee = find(:first, :include =\> [:account, :options],  
:conditions =\> [ “employees.deleted\_yn = 0” + " AND  
employees.username = ?" + " AND accounts.account\_code = ?",  
username, account\_code ])  
if employee  
expected\_password = encrypted\_password(password, employee.salt)  
if employee.hashed\_password != expected\_password  
employee = nil  
end  
end  
employee  
end  
end

# if employee = find… is line called for error

Thanks

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/2 "2008-03-10T17:21:38Z")

</div>

George P. wrote:

> \<% end %\> session[:user\_id] = employee.id
> 
> ```
> if employee
> 
> ```
> 
> Thanks
> 
> If you can post the stack trace from the error, that’ll help a lot.
> 
> One unrelated comment though; you don’t need to separate the different  
> strings and add them together in your find conditions. Just make it one  
> string…
> 
> [ “employees.deleted\_yn = 0 AND employees.username = ? AND  
> accounts.account\_code = ?”, username, account\_code ]
> 
> –  
> [http://www.5valleys.com/](http://www.5valleys.com/)  
> [http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)
> 
> | \<%= text\_field\_tag :username, params[:username] %\> |

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/3 "2008-03-10T20:04:57Z")

</div>

Here’s the trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/vendor/mysql.rb:566:in  
`initialize' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/vendor/mysql.rb:566:in `new’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/vendor/mysql.rb:566:in  
`scramble41' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/vendor/mysql.rb:144:in `real\_connect’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/connection\_adapters/mysql\_adapter.rb:389:in  
`connect' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/mysql_adapter.rb:152:in `initialize’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/connection\_adapters/mysql\_adapter.rb:82:in  
`new' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `mysql\_connection’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/connection\_adapters/abstract/connection\_specification.rb:262:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in `connection\_without\_query\_cache=’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/query\_cache.rb:54:in  
`connection=' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:230:in `retrieve\_connection’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/connection\_adapters/abstract/connection\_specification.rb:78:in  
`connection' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations.rb:1158:in `select\_all\_rows’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/associations.rb:1015:in  
`find_with_associations' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations.rb:1013:in `catch’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/associations.rb:1013:in  
`find_with_associations' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/base.rb:993:in `find\_every’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/base.rb:988:in  
`find_initial' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/base.rb:414:in `find’  
#{RAILS\_ROOT}/app/models/employee.rb:19:in `authenticate' #{RAILS_ROOT}/app/controllers/login_controller.rb:10:in `login’

Jon G. wrote:

> If you can post the stack trace from the error, that’ll help a lot.
> 
> One unrelated comment though; you don’t need to separate the different  
> strings and add them together in your find conditions. Just make it one  
> string…
> 
> [ “employees.deleted\_yn = 0 AND employees.username = ? AND  
> accounts.account\_code = ?”, username, account\_code ]
> 
> –  
> [http://www.5valleys.com/](http://www.5valleys.com/)  
> [http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 8:12pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/4 "2008-03-10T20:12:09Z")

</div>

Could be a framework mismatch with Rails. I think you see that if you  
have Rails \<= 1.2.4 and Ruby \>= 1.8.6

…and once you upgrade, your conditions can be even nicer:

:conditions=\>{:deleted\_yn=\>false, :username=\>username,  
:account\_code=\>account\_code}

On Mar 10, 3:04 pm, George P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 9:20pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/5 "2008-03-10T21:20:41Z")

</div>

_groan_  
Yesterday, I spent the day upgrading to Rails 2.0.2. How can I get my  
app to point to that instead. I tried changing environments.rb in my  
project to version 2.0.2, but that didn’t seem to work…

Jon G. wrote:

> AndyV wrote:
> 
> > Could be a framework mismatch with Rails. I think you see that if you  
> > have Rails \<= 1.2.4 and Ruby \>= 1.8.6
> 
> I agree.
> 
> –  
> [http://www.5valleys.com/](http://www.5valleys.com/)  
> [http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 8:45pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/6 "2008-03-10T20:45:30Z")

</div>

AndyV wrote:

> Could be a framework mismatch with Rails. I think you see that if you  
> have Rails \<= 1.2.4 and Ruby \>= 1.8.6

I agree.

–  
[http://www.5valleys.com/](http://www.5valleys.com/)  
[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/7 "2008-03-10T21:53:17Z")

</div>

On 10 Mar 2008, at 20:45, Frederick C. wrote:

> On 10 Mar 2008, at 19:04, George P. wrote:
> 
> > Here’s the trace
> 
> The problem is the upgrade to ruby 1.8.6 (which changed some things  
> in Digest, which is what’s being fiddled with on line 566).  
> Perhaps the easiest way around this is to use the native mysql  
> library (which is faster anyway)  
> Actually, going back through the changelogs I notice that the release  
> notes for 1.2.3 say ‘1.8.6 compatibility’, so anything prior to that  
> is probably asking for trouble.  
> Activerecord 1.5.1 is part of 1.2.1, so you’d want to at least upgrade  
> to 1.2.3 (which should be painless).

Fred

---

<div class="post-metadata">

**Author:** ![simplydope](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d26b3c/32.png) [@simplydope](https://www.ruby-forum.com/u/simplydope)\
**Post date:** [March 10, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/wrong-number-of-arguments-1-for-0/131451/8 "2008-03-10T21:47:17Z")

</div>

On 10 Mar 2008, at 19:04, George P. wrote:

> Here’s the trace

The problem is the upgrade to ruby 1.8.6 (which changed some things in  
Digest, which is what’s being fiddled with on line 566).  
Perhaps the easiest way around this is to use the native mysql library  
(which is faster anyway)

Fred
