# wrong number of arguments (1 for 0)

**URL:** <https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085>\
**Category:** rubyonrails-talk\
**Created:** [March 10, 2008, 6:37am UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085 "2008-03-10T06:37:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 10, 2008, 6:37am UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/1 "2008-03-10T06: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 %\>

\<table\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td colspan="2"\>\<font size = "4"\>\<b\>Sign-in to BancOffice\</b\>\</font\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>Company Code:\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= text\_field\_tag :account\_code, params[:account\_code] %\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>User name:\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= text\_field\_tag :username, params[:username] %\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>Password:\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= password\_field\_tag :password, params[:password] %\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= submit\_tag "Login" %\> \</td\> &nbsp;&nbsp;\</tr\> \</table\> \<% end %\>

---

<div class="post-metadata">

**Author:** ![J\_Garvin](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@J\_Garvin](https://discuss.rubyonrails.org/u/J_Garvin)\
**Post date:** [March 10, 2008, 4:20pm UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/2 "2008-03-10T16:20:28Z")

</div>

George Pasley wrote:

> 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 %\>
> 
> \<table\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td colspan="2"\>\<font size = "4"\>\<b\>Sign-in to BancOffice\</b\>\</font\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>Company Code:\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= text\_field\_tag :account\_code, params[:account\_code] %\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>User name:\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= text\_field\_tag :username, params[:username] %\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>Password:\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= password\_field\_tag :password, params[:password] %\>\</td\> &nbsp;&nbsp;\</tr\> &nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= submit\_tag "Login" %\> \</td\> &nbsp;&nbsp;\</tr\> \</table\> \<% end %\>
> 
> --------------------------- logincontroller.rb
> 
> def login &nbsp;&nbsp;&nbsp;&nbsp;session[:user\_id] = nil &nbsp;&nbsp;&nbsp;&nbsp;if request.post? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;employee = Employee.authenticate(params[:username], params[:password], params[:account\_code]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if employee &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session[:user\_id] = employee.id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session[:account\_id] = employee.account\_id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@option = Option.find\_by\_employee\_id(employee.id) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session[:admin\_yn] = @option.admin\_yn &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to(:controller =\> "dashboard", :action =\> "show") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "\<font color='red'\>Invalid user/password combination\</font\>" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end end
> 
> # employee.authenticate is line called for error --------------------------------
> 
> employee.rb
> 
> def self.authenticate(username, password, account\_code) &nbsp;&nbsp;&nbsp;&nbsp;if employee = find(:first, :include =\> [:account, :options], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:conditions =\> ["employees.deleted\_yn = 0" + " AND employees.username = ?" + " AND accounts.account\_code = ?", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username, account\_code]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if employee &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expected\_password = encrypted\_password(password, employee.salt) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if employee.hashed\_password != expected\_password &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;employee = nil &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;employee &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end
> 
> # if employee = find... is line called for error
> 
> Thanks &nbsp;&nbsp; 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]

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 10, 2008, 7:04pm UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/3 "2008-03-10T19: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 Garvin wrote:

---

<div class="post-metadata">

**Author:** ![AndyV1](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@AndyV1](https://discuss.rubyonrails.org/u/AndyV1)\
**Post date:** [March 10, 2008, 7:11pm UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/4 "2008-03-10T19:11:06Z")

</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}

---

<div class="post-metadata">

**Author:** ![J\_Garvin](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@J\_Garvin](https://discuss.rubyonrails.org/u/J_Garvin)\
**Post date:** [March 10, 2008, 7:43pm UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/5 "2008-03-10T19:43:45Z")

</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 &nbsp;&nbsp;

I agree.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 10, 2008, 8:20pm UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/6 "2008-03-10T20: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 Garvin wrote:

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [March 10, 2008, 8:45pm UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/7 "2008-03-10T20:45:10Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [March 10, 2008, 8:51pm UTC](https://discuss.rubyonrails.org/t/wrong-number-of-arguments-1-for-0/26085/8 "2008-03-10T20:51:35Z")

</div>

> > 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
